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?
For debug I usually use this
from pdb import set_trace; set_trace()
it may help
来源:https://stackoverflow.com/questions/7165493/how-to-get-python-interactive-console-in-current-namespace