I have a following code:
code = """
print("foo")if True: returnprint("bar")
"""exec(code)
print('This should still be executed')
If I run it I get:
Traceback (most recent call last):File "untitled.py", line 10, in <module>exec(code)File "<string>", line 5
SyntaxError: 'return' outside function
How to force exec
stop without errors? Probably I should replace return
with something? Also I want the interpreter work after exec
call.