我可以在嵌入式交互式Python控制台中使用IPython吗?
问题描述:
我使用下面的代码片段放入一个Python shell中程序。这工作正常,但我只得到标准控制台。有没有办法做到这一点,但使用IPython外壳?我可以在嵌入式交互式Python控制台中使用IPython吗?
import code
class EmbeddedConsole(code.InteractiveConsole):
def start(self):
try:
self.interact("Debug console starting...")
except:
print("Debug console closing...")
def print_names():
print(adam)
print(bob)
adam = "I am Adam"
bob = "I am Bob"
print_names()
console = EmbeddedConsole(locals())
console.start()
print_names()
答
通过f3lix答案不再有效看来,我能找到然而这样的:
在你的Python的顶部脚本:
from IPython import embed
不管你想要去旋转了一个控制台:
embed()
答
Embedding IPython可能对您有兴趣。
的最小值的代码在你的应用程序运行的IPython:
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed()
ipshell() # this call anywhere in your program will start IPython
+0
请看下面,现在有一个来自IPython的嵌入函数可以用来代替。 – 2014-04-09 00:46:38
请问您现在可以标记Dereck的答案吗? – 2015-10-06 01:36:21