[Python-Help] Globals
Carel Fellinger
cfelling at iae.nl
Sun Jan 28 13:29:32 EST 2001
Aleksei Guzev <aleksei.guzev at bigfoot.com> wrote:
...problem snipped
The global name scope of Python is the module scope.
So it's impossible to refer to entities in other modules
without importing those modules. e.g.
$ cat a.py
# module a
g_var = None
class CA:
def foo( self ):
print g_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"
va.foo()
$ python b.py
$ python c.py
the string to be printed
--
groetjes, carel
More information about the Python-list
mailing list