Created
March 10, 2011 18:44
-
-
Save baijum/864635 to your computer and use it in GitHub Desktop.
Exception alias and variable scope
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
>>> 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)