[issue26237] UnboundLocalError error while handling exception

2016-01-29 Thread Марк Коренберг
New submission from Марк Коренберг: This works right in Python 2.7, but fails in python3: UnboundLocalError: local variable 'e' referenced before assignment def test(): try: raise Exception('a') except Exception as e: pass else: return print(e) test()

[issue26237] UnboundLocalError error while handling exception

2016-01-29 Thread STINNER Victor
STINNER Victor added the comment: Yes, it's a deliberate change in the Python language. You have to copy "e" to a different variable: err = None try: ... except Exception as exc: err = exc print(err) -- nosy: +haypo resolution: -> not a bug status: open -> closed