Reputation: 1833
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
Upvotes: 2
Views: 167
Reputation: 369424
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
Upvotes: 3