0
>>> e = 'e'
>>> e
'e'
>>> try: raise Exception
except Exception as e:
    e = 'e'
    a = 'a'

>>> e
Traceback (most recent call last):
  File "<pyshell#333>", line 1, in <module>
    e
NameError: name 'e' is not defined
>>> a
'a'

I have not noticed this behavior before. Why is it that using a variable as a try-except alias makes it lose its previous definition?

uzumaki
  • 1,743
  • 17
  • 32
  • It's a strange side effect. `try`/`except` (like `if`/`else`) do not create a new namespace, so the `e` there is definitely going to wipe out your global `e`. The fact that it evaporates after the `except` is only slightly surprising, – Tim Roberts May 08 '21 at 04:31
  • @SuperStormer I think it does – uzumaki May 08 '21 at 04:38

0 Answers0