Variable passing between modules.

bbelguise at FT bbelguise at FT
Tue Sep 14 09:31:39 EDT 2004


>"Golawala, Moiz M (GE Infrastructure)" <Moiz.Golawala at ge.com> a écrit dans
le message news: >mailman.3094.1094735599.5135.python-list at python.org...
>The example that I provided was very simplistic. I have a tones of methods
in module 2 and the method >need to get executed and need the someVar value.

>I was thinking like setting up some a value in some global VM list which
can be accessed by all modules.

It's not pretty and it's a shame but you can do this
glob.py:
class glob_var:
    def __init__(self,Initial_Value):
        self.val=Initial_Value
var_glob=glob_var("Init")

a.py:
from glob import *
def fonca():
    global var_glob
    print "fonca -> ",var_glob.val,id(var_glob.val)

b.py:
from glob import var_glob
import a
def foncb():
    print "foncb -> ",var_glob.val,id(var_glob.val)
var_glob.val="glop"
print var_glob.val,id(var_glob.val)
foncb()
a.fonca()

and run b.py
"funny isn't it ?"





More information about the Python-list mailing list