callback confusion
Donn Ingle
donn.ingle at gmail.com
Sat Dec 8 12:46:46 EST 2007
> As far as I can tell, you have a bit more code in boo, and somewhere in
> that code (after the print statement), you rebind the name 'kills'.
Okay, yes:
def boo()
kills += 1
print kills
> the absence of a global declaration, this makes this name a local
> variable.
I think I see what you mean:
>>> kills=0
>>> def boo():
... kills += 1
... print kills
...
>>> print kills
0
>>> boo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in boo
UnboundLocalError: local variable 'kills' referenced before assignment
>>> kills=77
>>> def boo(): print kills
...
>>> boo()
77
I'm amazed that I've spent so much time with Python and something like that
totally stumps me!?
> FWIW, this is a FAQ.
If you have a link, that'll help.
\d
More information about the Python-list
mailing list