why does Configparser change names to lowercase ?

Rob Wolfe rw at smsnet.pl
Fri Sep 14 22:55:33 CEST 2007


stef mientki <stef.mientki at gmail.com> writes:

> hello,
>
> Why does  Configparser change names to lowercase ?
>
> As Python is case sensitive (which btw I don't like at all ;-)
> but now when really need the casesensitivity,
> because it handles about names which should be recognized by human,
> it changes everything to lowercase ????

I don't know why, but I know how to change it and I found the solution here:
http://docs.python.org/lib/RawConfigParser-objects.html

You need to change the implementation of method `optionxform`, e.g.:

# config
[section1]
option1=item1
Option2=item2
option2=item3

# cfg.py
from ConfigParser import ConfigParser

config = ConfigParser()
config.optionxform = str
config.read('config')
print config.get('section1', 'option1')
print config.get('section1', 'Option2')
print config.options('section1')

HTH,
Rob



More information about the Python-list mailing list