Any Python Hackers Wanna Beta Test????

Dave Brueck dave at pythonapocrypha.com
Tue Mar 9 21:13:44 EST 2004


Tim wrote:
> One of the things I find myself needing over and over is providing an
> external configuration file for use by my applications. For various
> reasons, I have not been satisfied with other solutions to this problem
> I have seen so far.
>
> So ...I am about 25% done with a new Python module I've wanted to write
> for some time. It is intended as general purpose configuration file
> parser complete with conditionals, variable substitution, etc. The idea
> is that you hand it the name of a configuration file, and it returns a
> populated symbol table, ready-to-use.

Just curious, but does it offer much over just doing this:

In a file called config.py:

optionA = 'foo'

optionB = 'bar'

class Network:
    optionC = 'baz'

And then in your application doing:

import config

config.optionA
config.Network.optionC

etc..?

That's what I use now and it pretty much does everything I want - the dummy
classes give an easy named hierarchy/grouping of values, and since it's just a
Python module you also get built-in support for conditionals, variable
substitution, etc. Also, you don't have to write code to do a bunch of syntax
verification since Python does that for you. I've used this on several projects
where the config file is editable by non-programmers and they haven't had any
problems. I usually stick in the config all the documentation for each setting
too.

-Dave





More information about the Python-list mailing list