473,372 Members | 1,075 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,372 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 3068
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
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.