[Python-Help] Globals

Aleksei Guzev aleksei.guzev at bigfoot.com
Sun Jan 28 02:43:57 EST 2001


 I meant the following doesn't work

	#
	# module A.py
	#

	class CA:
		def foo( self ):
			print g_var
		def __getstate__( self ):
			return "CA"
		def __setstate__( self, state ):
			print state


next file

	#
	# script B.py
	#

	import shelve
	import A

	va = A.CA()

	s = shelve.open( 's' )
	s[ "va" ] = va
	s.close()

the last file:

	#
	# C.py
	#	

	import shelve

	s = shelve.open( 's', 'r' )
	va = s[ "va" ]
	s.close()

	g_var = "the string to be printed"

	va.foo()

Run <B.py>. Next exit Python shell. Then restart the shell and run <C.py>. 
g_var whould be undefined in va.foo().






More information about the Python-list mailing list