Skip to content

Instantly share code, notes, and snippets.

@mahmoud
Created June 26, 2020 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahmoud/1f8a62aaaad9e178594c7d60dfa9e1d9 to your computer and use it in GitHub Desktop.
Save mahmoud/1f8a62aaaad9e178594c7d60dfa9e1d9 to your computer and use it in GitHub Desktop.
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