Search code examples
pythonconfigparser

What's the rationale of not preserving case (by default) in configparser?


If I want to preserve key names in a config file, I must add configparser.optionxform = str. I was surprised by this (configparser) behaviour, expecting case-preservation to be the default (if not the only) option.

Does this make sense to you? What's the rationale behind this decision?


Solution

  • This only affects the case of the option names, the case of values is always preserved. It can be argued, whether this is a sane choice, but the choice has been made and must now be followed in order to maintain compatibility with old sources.

    I don't see any big problem, since you obviously found a workaround for yourself. You might alternatively try configobj. It is powerful, has a much more convenient and reasonable API and does by default preserve case of options.