faqts : Computers : Programming : Languages : Python

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

22 of 25 people (88%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Why ConfigParser--does not preserve case in ConfigParser.options['mysection']

May 28th, 2001 00:29
Christopher Arndt, Mamoon Khan, ConfigParser.py


Dunno _why_ it behaves like this (maybe because windows, where this
kind of configuration file is common, is a non-case-distinguishing
system) but I it's in the source code, _how_ this is done:

Look into <pythonlibdir>/ConfigParser.py.
The culprit is in line 310 (Python 1.5.2) resp. line 468 (Python 2.1) in
method _read().
Also affected is the method get() and maybe others too.

In the version that comes with Python 2.1 you can change this behaviour
on the fly:

>>> import ConfigParser

>>> p = ConfigParser.ConfigParser()
>>> p.optionxform = lambda x: x
>>> p.read('win.ini')
>>> p.options('Windows Hilfe')
['H_WindowPosition', 'M_WindowPosition', 'C_WindowPosition']