Message85992
Consider the following two functions:
def outer():
a = 1
def inner():
print a
inner()
#end outer()
def outer_BUG():
a = 1
def inner():
print a
a = 2
inner()
#end outer_BUG()
The first function outer() works as expected (it prints 1), but the
second function ends with an UnboundLocalError, which says that the
"print a" statement inside inner() function references a variable before
assignment. Somehow, the interpreter gets to this conclusion by looking
at the next statement (a = 2) and forgets the already present variable a
from outer function.
This was observed with python 2.5.4 and older 2.5.2. Other releases were
not inspected.
Best regards,
Vid |
|
Date |
User |
Action |
Args |
2009-04-15 15:10:47 | vpodpecan | set | recipients:
+ vpodpecan |
2009-04-15 15:10:47 | vpodpecan | set | messageid: <1239808247.23.0.84220378754.issue5763@psf.upfronthosting.co.za> |
2009-04-15 15:10:44 | vpodpecan | link | issue5763 messages |
2009-04-15 15:10:42 | vpodpecan | create | |
|