Skip to content

Instantly share code, notes, and snippets.

@mahmoud
Created June 26, 2020 07:08
Show Gist options
  • Save mahmoud/1f8a62aaaad9e178594c7d60dfa9e1d9 to your computer and use it in GitHub Desktop.
Save mahmoud/1f8a62aaaad9e178594c7d60dfa9e1d9 to your computer and use it in GitHub Desktop.

Revisions

  1. mahmoud created this gist Jun 26, 2020.
    22 changes: 22 additions & 0 deletions py3_except.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    $ 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)
    """