Trouble accessing global vars
Fernando Rodríguez
fernandoSPAM.YOURSELF at fernando-rodriguez.com
Sat Sep 4 11:30:36 EDT 2004
Hi,
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()
b.run()
Traceback (most recent call last):
File "<pyshell#53>", line 1, in -toplevel-
b.run()
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
work?
More information about the Python-list
mailing list