Is it possible to temporarily disable Python's string interpolation?

Posted by dangerouslyfacetious on Stack Overflow See other posts from Stack Overflow or by dangerouslyfacetious
Published on 2010-03-29T12:49:28Z Indexed on 2010/03/29 12:53 UTC
Read the original article Hit count: 300

I have a python logger set up, using python's logging module. I want to store the string I'm using with the logging Formatter object in a configuration file using the ConfigParser module.

The format string is stored in a dictionary of settings in a separate file that handles the reading and writing of the config file. The problem I have is that python still tries to format the file and falls over when it reads all the logging-module-specific formatting flags.

{
    "log_level":logging.debug,
    "log_name":"C:\\Temp\\logfile.log",
    "format_string":
        "%(asctime)s %(levelname)s: %(module)s, line %(lineno)d - %(message)s"
}

My question is simple: how can I disable the formatting functionality here while keeping it elsewhere. My initial reaction was copious use of the backslash to escape the various percent symbols, but that of course permanently breaks the formatting such that it wont work even when I need it to.

Also, general pointers on good settings-file practices would be nice. This is the first time I've done anything significant with ConfigParser (or logging for that matter).

Thanks in advance, Dominic

© Stack Overflow or respective owner

Related posts about python

Related posts about string-interpolation