How to Lock Globar Variables across Modules?

William Djaja Tjokroaminata billtj at y.glue.umd.edu
Mon Sep 25 11:25:30 EDT 2000


Hi,

I am having this problem.  Suppose in 'module1.py' I declare a global
variable named 'globvar_mod1'.  In another module, called 'module2.py', I
have the statement 'from module import *'.

It looks like when I am running the program, the global variable in code
in module2 only refers to the initial value in module1, unless I use an
explicit name.  I.e., in module2:

    globvar_mod1            refers to the initial value in module1
    module1.globvar_mod1    refers to the current value in module1
                            (I also have to put 'import module1')

Specifying 'globvar_mod1 = module1.globvar_mod1' at the beginning of
module2 does not help.

Is there any way I can make 'globvar_mod1' in module2 to refer to the
current value of the global variable?  I don't want to use the long
explicit name, and I want to use something like 'gv =
module1.globvar_mod1' in module2 to lock gv to module1.globvar_mod1, i.e.,
they refer to the same object and changes whenever the object is
changed.  (The reference is not directly to the object but to the object
pointed by the other variable; I think it is like C++ or Perl reference.)

Thanks.


Regards,

Bill



More information about the Python-list mailing list