Is hilarious mistake in Python design. Thanks @elfprince13.

def x(): e = None while e is None: try: print(input("? ")) except Exception as e: print(repr(e))x()

Result:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in xUnboundLocalError: local variable 'e' referenced before assignment

@radehi @elfprince13 none will be able to appreciate the code you've shared if you don't post it indented, so we can reproduce. I'd suggest you to use a website like pastebin for this. Python without indentation is impossible to read...

@elfprince13 @radehi Thanks. I can confirm that this happens in python 3.9.15 too, when I press CTRL+C to break the while loop. Anyhow, I wouldn't exactly blame python for creating a function with side effects.

@mlliarm @elfprince13 The problem is not that a function has side effects.

Sign in to participate in the conversation
Mastodon

General topic personal server.