I would like to create a simple python shell. So right now I am stuck on executing the code. The question is, is there a way to run exec with custom globals? Thanks
1 Answer
You can pass custom global dictionary as follow:
a, b = 1, 2
exec('print(a+b)', {'a': 5, 'b': 5}) # prints 10
Reference: The exec statement