469,282 Members | 2,001 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

configparser shuffles all sections ?

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
Jun 22 '07 #1
7 2966
In <ma***************************************@python. org>, stef wrote:
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
Jun 22 '07 #2
Marc 'BlackJack' Rintsch wrote:
In <ma***************************************@python. org>, stef wrote:

>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.
So there should be some way to sort it ?
>
>This makes human manipulation of the file impossible.

Why so?
I've about 1000 sections ;-)
Ciao,
Marc 'BlackJack' Rintsch
thanks,
Stef Mientki
Jun 22 '07 #3
stef <s.*******@id.umcn.nlwrote:
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()

--
Nick Craig-Wood <ni**@craig-wood.com-- http://www.craig-wood.com/nick
Jun 22 '07 #4
On Fri, 22 Jun 2007 09:28:42 +0200, stef wrote:
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.
--
Steven

Jun 22 '07 #5
Nick Craig-Wood wrote:
stef <s.*******@id.umcn.nlwrote:
> 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 ;-)

cheers,
Stef Mientki
Jun 22 '07 #6
On Jun 22, 8:28 pm, Stef Mientki <S.Mientki-nos...@mailbox.kun.nl>
wrote:
Nick Craig-Wood wrote:
stef <s.mien...@id.umcn.nlwrote:
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

Jun 23 '07 #7
On Jun 23, 1:14 am, Fuzzyman <fuzzy...@gmail.comwrote:
On Jun 22, 8:28 pm, Stef Mientki <S.Mientki-nos...@mailbox.kun.nl>
wrote:
Nick Craig-Wood wrote:
stef <s.mien...@id.umcn.nlwrote:
> 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
Oh - and as a bonus, it preserves comments.
http://www.ironpython.info
>

cheers,
Stef Mientki

Jun 23 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Greg Krohn | last post: by
1 post views Thread by Martin Maney | last post: by
11 posts views Thread by Manlio Perillo | last post: by
1 post views Thread by Alexandre CONRAD | last post: by
1 post views Thread by Nexu | last post: by
1 post views Thread by pipehappy | last post: by
4 posts views Thread by Phoe6 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.