Skip to content

Instantly share code, notes, and snippets.

@wolever
Created March 1, 2014 01:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolever/9283224 to your computer and use it in GitHub Desktop.
Save wolever/9283224 to your computer and use it in GitHub Desktop.
"""
Python 2:
$ python-2.7 finallyfun.py
e: Exception()
Python 3:
$ python3.3 finallyfun.py
Traceback (most recent call last):
File "finallyfun.py", line 9, in <module>
foo()
File "finallyfun.py", line 7, in foo
print("e: %r" %(e, ))
UnboundLocalError: local variable 'e' referenced before assignment
"""
def foo():
e = None
try:
raise Exception()
except Exception as e:
pass
finally:
print("e: %r" %(e, ))
foo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment