Accessing and updating global variables among several modules

Fuming Wang fumingw at
Sat Jul 12 05:38:48 CEST 2003


I have several modules that need to access global variables among
them.  I can do that by import modules:

module A:
gA = 'old'

module B:
import A
print A.gA
>>> 'old'

change gA in module A after some initialization:
def init_fuct():
    gA = 'new'

no change in module B:
print A.gA
>>> 'old'

However, when I modify these global variables in one module, the other
modules would not see the changes.  Any one has any suggestions? ( I
don't want to use from A import *)


More information about the Python-list mailing list