On May 5, 6:57 pm, Matimus <[EMAIL PROTECTED]> wrote:
> On May 5, 10:22 am, Francesco Bochicchio <[EMAIL PROTECTED]> 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.

Read the caveats in reload()'s description. Briefly:
- It does not reload names imported with "from  ... import ...".
- Any existing instances of classes defined in the module still refer
to the original class, not the reloaded one (assuming it is still
present).
- The module's dictionary (containing the module's global variables)
is retained and updated in place, so names that are deleted in the
module are still available.
- It is not recursive.
- And more...

George
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to