by abstractbill · 17y ago · 0 comments
>>> def foo():
... blah = 42
... def wibble():
... print "blah is " + blah
... wibble()
...
>>> foo()
blah is 42
Great! Looks like we have real closures! >>> def foo():
... blah = 42
... def wibble():
... blah += 1
... wibble()
... print "blah is " + blah
...
>>> foo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 5, in foo
File "<stdin>", line 4, in wibble
UnboundLocalError: local variable 'blah' referenced before assignment
Oh. Maybe not.I agree it's broken, but it's a different flaw than the closure problem.