2

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 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.