Message108306
Description:
An unexpected UnboundLocalError is produced when assigning a value to a variable inside a nested function. The first assignment to the variable is in the enclosing function.
Example:
def x():
a = False
def y():
print a
a = True
return y
Calling x()() produces an UnboundLocalError on the 'print a' line.
If the 'a = True' line is removed, no error occurs.
Tested with:
- 2.5.1
- 2.6.5
Keywords:
Nested function, UnboundLocalError, variable assignment
Thank you for your attention |
|
Date |
User |
Action |
Args |
2010-06-21 19:46:39 | Andreas Hofmeister | set | recipients:
+ Andreas Hofmeister |
2010-06-21 19:46:39 | Andreas Hofmeister | set | messageid: <1277149599.18.0.763779339646.issue9049@psf.upfronthosting.co.za> |
2010-06-21 19:46:37 | Andreas Hofmeister | link | issue9049 messages |
2010-06-21 19:46:37 | Andreas Hofmeister | create | |
|