Global package variable, is it possible?

Carsten Haese carsten at uniqsys.com
Fri Aug 3 14:16:59 EDT 2007


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 Haese
http://informixdb.sourceforge.net





More information about the Python-list mailing list