Preserve case in ConfigParser? Preserve case in ConfigParser? python python

Preserve case in ConfigParser?


The documentation is confusing. What they mean is this:

import ConfigParser, osdef get_config():    config = ConfigParser.ConfigParser()    config.optionxform=str    try:        config.read(os.path.expanduser('~/.myrc'))        return config    except Exception, e:        log.error(e)c = get_config()  print c.options('rules')

I.e. override optionxform, instead of calling it; overriding can be done in a subclass or in the instance. When overriding, set it to a function (rather than the result of calling a function).

I have now reported this as a bug, and it has since been fixed.


For me worked to set optionxform immediately after creating the object

config = ConfigParser.RawConfigParser()config.optionxform = str


Add to your code:

config.optionxform = lambda option: option  # preserve case for letters