Help with ConfigParser

Peter Otten __peter__ at web.de
Mon Oct 2 09:50:57 EDT 2006


tony.ha at philips.com wrote:

> Question: How can I pervent ConfigParse to convert Upper case yo lower
> case??, thanks.

http://docs.python.org/dev/lib/RawConfigParser-objects.html

"""
optionxform(option)

Transforms the option name option as found in an input file or as passed in
by client code to the form that should be used in the internal structures.
The default implementation returns a lower-case version of option;
subclasses may override this or client code can set an attribute of this
name on instances to affect this behavior. Setting this to str(), for
example, would make option names case sensitive. 
""""

If you don't pass defaults:

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

Or, to be on the safe side:

class MyCasePreservingConfigParser(ConfigParser):
    optionxform = str

config = MyCasePreservingConfigParser()
# ...

Peter



More information about the Python-list mailing list