F
Fernando Rodríguez
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?
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?