Re: ANN : ConfigObj 3.0.0 - Simple config file parsing

From: David Fraser (davidf_at_sjsoft.com)
Date: 05/28/04


Date: Fri, 28 May 2004 10:10:27 +0200

Fuzzyman wrote:
> There have been a couple of config file 'systems' announced recently,
> that focus on building more powerful and complex configuration files.
> ConfigObj is a module to enable you to much more *simply* access
> config files.
>
> This is version 3, which is a big overhaul. It extends ConfigObj to
> reading config files with sections and various other simplifications.
> I find ConfigObj extremely easy to use and use it for reading config
> files and data persistence......
>
> http://www.voidspace.org.uk/atlantibots/pythonutils.html#configobj
>
> (also the home of caseless and listparse modules)
>
> INTRODUCTION and EXTRACT from docs
>
> ConfigObj
>
> ConfigObj allows you to read, modify and create config files in python
> with basically single line commands.
> If you give it a filename it will read the config automatically and
> you can access or change the values by treating it like a dictionary.
> ConfigObj 3 is a major upgrade to ConfigObj - it will now read and
> write config files with sections (like windows INI files) as well as
> various other improvements and simplifications.
>
>
> ConfigObj has the following advantages over other configuration
> systems :
> Ease of use
> Multiple (list) values for keywords
> Easy to create, modify *and* write files
> Easy to hand edit/create the config files
> comments are preserved
> quoting is optional
> will understand various different keyword/value dividers
>
> Because the programmers interface is the same as the Python
> dictionary, ConfigObj is also extremely useful for data persistence.
> The fact that it can store lists and all the files it creates are
> easily 'human readable' is a big plus for this. Most functionality can
> be achieved with dictionary like syntax.
>
> So it implements a system that is easy for your users to use and easy
> for you to examine the files that it creates.
> Feedback on this module, including the documentation, is very much
> welcomed. Questions, criticism, comments, bug reports and suggestions
> all welcomed.
>

Just as an aside, we've just written a config system for our app that I
think is quite interesting and am planning to release when I get time.

Some of the goals are the same as ConfigObject: easy for either a human
or a computer to read / edit the files.
Some are different. Particularly it handles hierarchical config tries in
a nice pythonic syntax. For example you can specify things like this:

app1.title = "Title of app"
app1.font.face = "Arial"

Or like this:

app1:
   title = "Title of app"
   font.face = "Arial"

You can also copy bits of the tree if you like:

app1:
   title = "Title of app"
   subtitle = "Red"
   font:
     face = "Arial"
     size = 16
     style = "normal"

app2:
   title = "Other title"
   subtitle = app1.subtitle
   font = app1.font:
     size = 18

The module will automatically remember where an element is defined and
save changed values to the same location. It will also save new values
to an appropriate location (e.g. app2.newvalue would appear in the app2
section).

I think the hierarchical aspect of configuration is important ; it lets
you do things like Mozilla's generic prefs interface etc. It also gives
plugins / customizations to an app an easy way to add their own preferences.

If anyone is interested in this module, post a reply...

David