Global package variable, is it possible?

Chris Allen ca.allen at gmail.com
Fri Aug 3 15:05:29 EDT 2007


On Aug 3, 11:16 am, Carsten Haese <cars... at uniqsys.com> wrote:
> On Fri, 2007-08-03 at 17:51 +0000, Fabio Z Tessitore wrote:
> > Heve you tried to do something like:
>
> > # module configure.py
> > value1 = 10
> > value2 = 20
> > ...
>
> > # other module
> > from configure import *
>
> > # now I'm able to use value1 value2 etc.
> > var = value1 * value2
>
> Right idea, wrong execution. Note that the OP said "I'd like to be able
> to reload the config file dynamically and have all my modules
> automatically receive the new config."
>
> "from configure import *" will import the settings into the current
> namespace, and subsequent changes in the original namespace will, in
> general, not have any effect in the current namespace.
>
> This should do the trick:
>
> # module configure.py
> value1 = 10
> value2 = 20
> ...
>
> # other module
> import configure
>
> var = configure.value1 * configure.value2
>
> HTH,
>
> --
> Carsten Haesehttp://informixdb.sourceforge.net

It does help thanks.  Okay now after reading your post I really need
to do some experimenting.  I was under the impression when I wrote my
last post that changing an attribute in one modules instance in
__init__.py would not effect other modules.  Sorry, I'm relatively new
to python, and things like this are still sometimes "gotchas!" for me.




More information about the Python-list mailing list