config files in python

Francesco Bochicchio bockman at virgilio.it
Mon May 5 13:22:32 EDT 2008


On Mon, 05 May 2008 00:35:51 -0700, sandipm wrote:

> Hi,
>  In my application, I have some configurable information which is used
> by different processes. currently I have stored configration in a
> conf.py file as name=value pairs, and I am importing conf.py file to
> use this variable. it works well
> 
> import conf
> print conf.SomeVariable
> 
> but if I need to change some configuration parameteres,  it would need
> me to restart processes.
> 
> I want to store this data in some conf file (txt) and would like to
> use it same way as I am using these variables as defined in py
> files.
> 
> one solution I can think of is writing data as a dictionary into conf
> file. and then by reading data, apply eval on that data. and update
> local dict? but this is not a good solution....
> 
> any pointers?
> 
> Sandip

 The 'simple but relatively dangerous way', already suggested, is to
 reload() the module. 

A safer way - but requiring more work - could be to build something around
the Configparser module in the standard library ...

Ciao
-----
FB



More information about the Python-list mailing list