Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
python3 exception var deleting
$ python3
Python 3.7.7 (default, Mar 10 2020, 17:25:08)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> e = 'hi'
>>> try:
... 1/0
... except Exception as e:
... pass
...
>>> e
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'e' is not defined
>>>
"""
What might first be understood as a scoping improvement in python3 was
actually a side effect of adding traceback references to exceptions, and
yields this funky variable name deletion issue. It's all to avoid memory leaks
(e.g., when you catch an exception at the module level)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment