FYI: ConfigParser, ordered options, PEP 372 and OrderedDict + big thank you

Jonathan Fine J.Fine at open.ac.uk
Tue Nov 17 11:59:44 EST 2009


Hi

A big thanks to Armin Ronacher and Raymond Hettinger for
    PEP 372: Adding an ordered dictionary to collections

I'm using ConfigParser and I just assumed that the options in a section 
were returned in the order they were given.  In fact, I relied on this fact.
     http://docs.python.org/library/configparser.html

And then when I came to test the code it went wrong.  After some anguish 
I looked at ConfigParser and saw I could pass it a dict_type.  So I 
could fix the problem myself by writing an OrderDict.  Which I duly 
prototyped (in about an hour).

I then thought - maybe someone has been down this path before.  A Google 
search quickly led me to PEP 372 and hence to
     http://docs.python.org/dev/py3k/library/configparser.html
which says
     class configparser.RawConfigParser(defaults=None,
                dict_type=collections.OrderedDict)

So all that I want has been done already, and will be waiting for me 
when I move to Python3.

So a big thank you is in order.

-- 
Jonathan



More information about the Python-list mailing list