Reading/Writing Config Files

Tony Meyer ta-meyer at ihug.co.nz
Thu Aug 21 17:44:49 EDT 2003


> 1. ConfigParser: does not preserve order of entries in the 
> config file and comments when updating the file.  This is 
> critical since people are going to be reading/updating those 
> files as well.
[...]
> Are there other libraries I should look at?  Should I just 
> write one myself (or clean up [2] or [3]) ?  I can't believe 
> there isn't something better available for such a common task...

I ran into this when making some changes to the SpamBayes options code, too.
I was also surprised that there didn't seem to be anything around, and ended
up making a enhanced version of [1].  I was meant to submit this as a patch
in case the Python people were interested, but haven't yet got around to it
(for one reason, the use by SpamBayes changed a couple of times).

Note that it's a much more difficult task to enhance [1] in Python 2.2
because all the attributes that you need to override are private.  This is
fixed in Python 2.3.

If you want it, you can find it in the source for SpamBayes (in case you
don't know, the PSF holds the copyright to SpamBayes and it's released under
the PSF license, just like Python itself).  There's a module in the
spambayes/spambayes attic called UpdatableConfigParser.py, which is a
standalone module that does what you're after.  There's also the file
spambayes/spambayes/Options.py, which contains a version of this, but isn't
standalone.

<http://spambayes.org>

FWIW and HTH.

=Tony Meyer






More information about the Python-list mailing list