Created
March 25, 2010 23:58
-
-
Save esamattis/344287 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def works_fine(value=""): | |
def closure(): | |
if not value: | |
return "something" | |
return value | |
return closure | |
def does_not_work(value=""): | |
def closure(): | |
if not value: | |
value = "something" | |
return value | |
return closure | |
# Prints "something" | |
print works_fine()() | |
# Should also print "something"? | |
print does_not_work()() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
something | |
Traceback (most recent call last): | |
File "/home/epeli/ohjelmointi/Subuser/subssh/poista.py", line 36, in <module> | |
print does_not_work()() | |
File "/home/epeli/ohjelmointi/Subuser/subssh/poista.py", line 24, in closure | |
if not value: | |
UnboundLocalError: local variable 'value' referenced before assignment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment