Skip to content

Instantly share code, notes, and snippets.

@baijum
Created March 10, 2011 18:44
Show Gist options
  • Save baijum/864635 to your computer and use it in GitHub Desktop.
Save baijum/864635 to your computer and use it in GitHub Desktop.
Exception alias and variable scope
>>> e = "Hello"
>>> try:
x = int("foo")
except ValueError as e:
print("Horror!")
print(e)
Horror!
invalid literal for int() with base 10: 'foo'
>>> e
Traceback (most recent call last):
File "<pyshell#36>", line 1, in <module>
e
NameError: name 'e' is not defined
@orsenthil
Copy link

Did you really stumble upon this or a demonstration?
except ValueError as v:
print (v)
Should make it lesshorror.py :)

Answer seems to be here: http://goo.gl/mod/bjTw (because of a certain Python3 expect as behavior)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment