473,325 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 3067
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Greg Krohn | last post by:
I'm trying to subclass ConfigParser so I can use a custom __read method (the custom format doesn't conform to RFC 822) when needed. Needless to say, it's not working as expected. In the...
1
by: Martin Maney | last post by:
Summary: with batteries like these, get a longer extension cord? <transcript from interactive session> Python 2.2.1 (#1, Sep 7 2002, 14:34:30) on linux2 Type "help", "copyright",...
3
by: S.Ramaswamy | last post by:
I am trying unsuccessfully to set the order of options using the set(section,option,value) method ( Python 2.2.2) and writing to a file. But the options always appear in a random order. Before...
11
by: Manlio Perillo | last post by:
Regards. Since sections in CongiParser files are delimited by , why there is not an escape (and unescape) function for escaping &, characters to &amp;, &lbrack; and &rbrack; ? Thanks ...
1
by: Alexandre CONRAD | last post by:
Hello list ! I'm using the ConfigParser module to use configuration files (what else would it be for ?). But I have a dilema: I'd like to setup multiple "update server" for my application with...
1
by: Nexu | last post by:
Hello, I'm not sure exactly what i'm doing wrong here. I asked around on IRC and i was told the code is correct. The purpose of Settings() is that whenever Settings() or any of its methods are...
1
by: pipehappy | last post by:
Hello everyone: I came across the module ConfigParser and can use it correctly. import ConfigParser fp = open('test.cfg','w+') config = ConfigParser.ConfigParser() config.readfp(fp)...
4
by: Danil Dotsenko | last post by:
Wrote a little "user-friedly" wrapper for ConfigParser for a KDE's SuperKaramba widget. (http://www.kde-look.org/content/show.php?content=32185) I was using 2.4.x python docs as reference and...
4
by: Phoe6 | last post by:
Hi, I have a configfile, in fact, I am providing a configfile in the format: Name: Foo Author: Bar Testcases: tct123
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.