Skip to content

Instantly share code, notes, and snippets.

@esamattis
Created March 25, 2010 23:58
Show Gist options
  • Save esamattis/344287 to your computer and use it in GitHub Desktop.
Save esamattis/344287 to your computer and use it in GitHub Desktop.
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()()
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