When I run:
exec("print(__name__)")
it prints __main__.
But when I run:
exec("print __name__", {})
it prints builtins.
How to make the second example to also print __main__?
What I try to achieve is to run a piece of code with exec() so that from the perspective of the it looks like it was run from command line.
I would like to tun the code with clean scope but the second example breaks the code relying on if __name__ == "__main__". How to fix this?