Global confusion

skaller skaller at maxtal.com.au
Tue Sep 28 18:43:35 EDT 1999


David Ascher wrote:
[global directive]

> Side note 2: JPython does something else altogether.

Can you elaborate please?

> Side note 3: Since you do want to modify the global variable, adding the
>              global declaration is the right thing to do.

	There is a better technique, not requiring 'global' ,
which even Guido dislikes: use a module level class instance,
and assign to an attribute of it: one level of indirection defeats the
localisation:

	class X(): pass
	x = X()
	def f(y):
		x.y =1 # assign to attribute of global instance


-- 
John Skaller, mailto:skaller at maxtal.com.au
1/10 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
downloads: http://www.triode.net.au/~skaller




More information about the Python-list mailing list