ANN: New configuration module released

Vinay Sajip vinay_sajip at red-dove.com
Thu Nov 4 06:00:32 EST 2004


Sylvain Thenault wrote:
> the "configuration" module in logilab's common library is doing this (make
> a bridge between optparse and ConfigParser). You give a kind of
> configuration schema to a configuration object and then it can be
> initialized from a configuration file and/or command line. Environment
> variable are not considered yet, but I don't think it would be hard to add
> this feature. The main problem is the lack of documentation, but if there
> is some interest I can post an usage example.

I'm interested to see how your bridging works.

Using the config module I released, access to environment variables is
very easy. Here's how:

1. Add the line

os : `os`

to your configuration (say, test.cfg).

2. Access it like this:

>>> from config import Config
>>> cfg = Config(file('test.cfg'))
>>> cfg.os.environ['OS']
'Windows_NT'

The point, of course, is that you can refer to environment variables
from elsewhere in your configuration, e.g.

temp_path: `os.environ['TEMP']`
work_file_prefix: $temp_path + `os.sep`

Best regards,


Vinay Sajip




More information about the Python-list mailing list