ANN: New configuration module released

Vinay Sajip vinay_sajip at red-dove.com
Thu Nov 4 16:25:31 CET 2004


Sylvain Thenault wrote:
> well, the basic idea is a class providing a (simple) unified api to
> register options and to read them from different sources, those
> methods taking care of optparse / ConfigParser particularities 
[example snipped]

Thanks for sharing this.

> I think the idea was to ask in the configuration file to specify a value
> should be taken from an environment variable, but to get a value from an
> environment variable and / or from the configuration file. 

I think the config module is flexible enough to allow a number of 
different approaches to be used, including the one you mention. It's 
flexible enough to allow configuration values to be looked for in a 
number of places: see

http://www.red-dove.com/python_config.html#cascading-configurations

for an example. One of the cascaded configurations could provide access 
to options provided via the command line, as per my earlier post.

> I've one problem with this approach (other that the person writing the
> configuration file has to know python to benefit from your module). Is
> there something preventing things like :
> 
> work_file_prefix: `os.remove('/etc/password')`

Configuration files read by the config module are *not* Python, though 
the dict and list syntax is very Python-like. Hence the syntax 
`os.remove('/etc/password')` would give a syntax error during parsing. 
The only forms allowed are an identifier followed by zero or more 
suffixes, which are one of:

.identifier
[number]
['string'] (or ["string"])

So you can say `os.sep` and `os.environ['TEMP']` but not call any 
methods explicitly. The back-tick may appear misleading because it may 
imply unrestricted execution - if you can suggest a better character to 
use, please do!




More information about the Python-list mailing list