Imports awareness in Imported modules problem
alex23
wuwei23 at gmail.com
Sun Aug 24 08:25:54 EDT 2008
On Aug 24, 9:43 pm, "Mohamed Yousef" <harrr... at gmail.com> wrote:
> but what about module-wide variables what is the approach to them ,
> will i have to store them in a memory table (SQL) , or keep passing
> them between objects - which i really hate -
If you have a set of global variables that you want to share among
modules, put them all into a module.
config.py:
var1 = 'a'
a.py:
import config
config.var1 = 'z'
b.py:
import config
print config.var1
>>> import a
>>> import b
z
A module is only really imported once; each subsequent import is given
a reference to that imported module, so any changes to the module
values are shared amongst each importing module.
More information about the Python-list
mailing list