如何在当前命名空间中获取Python交互式控制台? [英] How to get Python interactive console in current namespace?
问题描述
我想让我的Python代码在运行代码中使用类似code.interact()的代码启动一个Python交互式控制台(REPL)。但是code.interact()启动的控制台看不到当前命名空间中的变量。如何执行类似的操作:
mystring =hello
code.interact >
...然后在启动的交互式控制台中,我应该能够键入mystring并获取hello。这可能吗?我需要设置code.interact()的local参数的东西吗?这将设置什么?
尝试:
code.interact(local = locals())
http://aymanh.com/python-debugging-techniques )
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?
Try:
code.interact(local=locals())
(found here: http://aymanh.com/python-debugging-techniques)
这篇关于如何在当前命名空间中获取Python交互式控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!