[issue9049] UnboundLocalError in nested function

2010-06-22 Thread Mark Dickinson
Mark Dickinson added the comment: > Is there any way to produce the desired behavior? Not directly, in Python 2.x. (But there's the 'nonlocal' keyword in 3.x.) There are various workarounds, but what's best depends on what you're doing. The python-list mailing list is probably a better pla

[issue9049] UnboundLocalError in nested function

2010-06-21 Thread Andreas Hofmeister
Andreas Hofmeister added the comment: Thank you for your assistance. I apologize for not examining the reference manual closely. Is there any way to produce the desired behavior? I currently work around the local name binding like this: def x(): a = [False] def y(): print

[issue9049] UnboundLocalError in nested function

2010-06-21 Thread Éric Araujo
Changes by Éric Araujo : -- stage: -> committed/rejected ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http:/

[issue9049] UnboundLocalError in nested function

2010-06-21 Thread Mark Dickinson
Mark Dickinson added the comment: This isn't a bug; it's by design. Because there's an assignment to 'a' in the function 'y', 'a' is considered local to that function. (It doesn't matter where the assignment happens within the function; the presence of an assignment anywhere is enough to m

[issue9049] UnboundLocalError in nested function

2010-06-21 Thread Andreas Hofmeister
New submission from Andreas Hofmeister : 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