In Python this works:
exec('x = 1; y = 2')
so you have both x and y created successfully:
>>> x,y
(1,2)
But this does not work:
def DoIt():
exec('x = 1; y = 2')
return x,y
>>> DoIt()
...
NameError: name 'x' is not defined
Why? Any solution?
================================================
Edit: Very Strange and Unexpected: The above works on Python 2.7
Check out on https://repl.it/languages/python
Anyway, I am using Python 3.5 64Bit and it does not work at all! The Python 2.7 is not a solution for me.
This post requires in depth knowledge of an experienced Pythonist.
Dear New Comers, first, very welcome to Stackoverflow! and WoW you started your journey with downvoting without even paying attention to what the question is all about! You can do better, be patient. Leave comments, it is OK and recommended.
And BTW, what matters to me after all is an answer to my question.
[Note]
This is not a duplicate of another question. I had to do no business with Python 2.7 to see a difference. Such bizarre behavior was discovered here following comments and previous (now deleted) answers.
So when something like this happens, you do not go to check you code if running differently in previous versions of Python. You just do not. So recommendation on this regards is irrelevant.