Trouble accessing global vars

Fernando Rodríguez fernandoSPAM.YOURSELF at
Sat Sep 4 17:30:36 CEST 2004


I haven't used Python in quite some time, and I'm bit puzzled by this:

counter = 0

class Blah(object):
	def run(self):
		counter += 1

b = Blah()

Traceback (most recent call last):
  File "<pyshell#53>", line 1, in -toplevel-
  File "<pyshell#51>", line 3, in run
    counter += 1
UnboundLocalError: local variable 'counter' referenced before assignment

However, counter is not a local var, it's a global one. :-? Shouldn't this

More information about the Python-list mailing list