config files in python

Matimus mccredie at gmail.com
Mon May 5 18:57:52 EDT 2008


On May 5, 10:22 am, Francesco Bochicchio <bock... at virgilio.it> wrote:
> 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

How is it relatively dangerous? I mean, aside from any `dangers'
associated with importing a user defined module in the first place.

Matt



More information about the Python-list mailing list