ignoring some placeholders in string formatting

Discussion in 'Python' started by Michal Ludvig, Feb 11, 2010.

  1. Hi all,

    when I've got a string, say:


    is it possible to fill in only 'session' and leave "%(message)s" as is
    when it isn't present in the values dict?

    For example:
    URL % { 'session' : 123 }
    raises KeyError because of missing 'message' in the dict.

    I could indeed replace '%(session)s' with a string replace or regexp but
    that's not very elegant ;-)

    Is there any way to tell the formatter to use only what's available and
    ignore the rest?


    Michal Ludvig, Feb 11, 2010
    1. Advertisements

  2. Steven D'Aprano, Feb 11, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.