configparser shuffles all sections ?

Fuzzyman fuzzyman at gmail.com
Sat Jun 23 02:14:59 CEST 2007


On Jun 22, 8:28 pm, Stef Mientki <S.Mientki-nos... at mailbox.kun.nl>
wrote:
> Nick Craig-Wood wrote:
> > stef <s.mien... at id.umcn.nl> wrote:
> >>  I just used configparser for the first time and discovered that it
> >>  shuffled all my sections,
> >>  and the contents of the sections too.
>
> >>  This makes human manipulation of the file impossible.
>
> >>  Is there a way to prevent this shuffling,
>
> > You could try getting yourself an ordered dictionary implmentation,
> > say
>
> >  http://www.voidspace.org.uk/python/odict.html
>
> > Then doing something like this (untested)
>
> >     class MyConfigParser(SafeConfigParser):
> >         def __init__(self, defaults=None):
> >             SafeConfigParser.__init__(defaults)
> >             self._sections = odict()
> >             self._defaults = odict()
>
> This might be good alternative,
> I'll check that.
>
> thank you all for the answers,
> it's always good to know that I've not missed the simple solution ;-)


There's one simple solution - ConfigObj.

It is a config file reader and preserves order:

http://www.voidspace.org.uk/python/configobj.html

Fuzzyman
http://www.ironpython.info

>
> cheers,
> Stef Mientki





More information about the Python-list mailing list