user553702 user553702 - 1 month ago 16
Python Question

How to get Python interactive console in current namespace?

I would like to have my Python code start a Python interactive console (REPL) in the middle of running code using something like code.interact(). But the console that code.interact() starts doesn't see the variables in the current namespace. How do I do something like:

mystring="hello"

code.interact()

... and then in the interactive console that starts, I should be able to type mystring and get "hello". Is this possible? Do I need to set the "local" argument of code.interact() to something? What would this be set to? How should it be called?

Answer

Try:

code.interact(local=locals())

(found here: http://aymanh.com/python-debugging-techniques)