[Python-Help] Globals
Aleksei Guzev
aleksei.guzev at bigfoot.com
Sun Jan 28 21:34:21 EST 2001
THis works well while You do know what module is va imported from ;) I mean
c.py conclude somehow to "import a".
But I thought on this question last night and understood that I could defile
a static variable of class CA referring g_var. This static variable should
be initialized not from shelve but in c.py.
$ cat a.py
# module a
class CA:
var = None
def foo( self ):
print self.var
$ cat b.py
# module b
import shelve, a
s = shelve.open( 's' )
s[ "va" ] = a.CA()
s.close()
$ cat c.py
# module c
import shelve, a
s = shelve.open( 's', 'r' )
va = s[ "va" ]
s.close()
a.g_var = "the string to be printed"
CA.var = g_var
va.foo()
$ python b.py
$ python c.py
the string to be printed
--
groetjes, carel
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list