configparser shuffles all sections ?

S

stef

hello,

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,
or are there other libraries that can handle windows ini-files without
reshuffling ?

thanks,
Stef Mientki

Kamer van Koophandel - handelsregister 41055629 / Netherlands Chamber of Commerce - trade register 41055629
 
M

Marc 'BlackJack' Rintsch

I just used configparser for the first time and discovered that it
shuffled all my sections, and the contents of the sections too.

The data is stored in dictionaries.
This makes human manipulation of the file impossible.

Why so?

Ciao,
Marc 'BlackJack' Rintsch
 
N

Nick Craig-Wood

stef said:
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()
 
S

Steven D'Aprano

hello,

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.

Having read the rest of this thread, I think Stef is not worried about
*human* manipulation. There is nothing stopping a human from editing the
INI file in a text editor, except perhaps the sheer size of the file.

But what I think is the actual problem is that, having read the INI file
into dictionaries, the order is lost. For that matter, so are comments,
and probably whitespace. That makes it impractical to generate an INI
file, then read it with configparser, make changes to the configparser
data, then write it back to the INI file.

Unfortunately, I don't think configparser can deal with that, and I'm not
aware of any libraries that will.
 
S

Stef Mientki

Nick said:
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 ;-)

cheers,
Stef Mientki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top