我可以在嵌入式交互式Python控制台中使用IPython吗? [英] Can I use IPython in an embedded interactive Python console?
本文介绍了我可以在嵌入式交互式Python控制台中使用IPython吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码段放入Python shell中间程序。这工作正常,但我只得到标准控制台。是否有同样方法,但使用 IPython shell?
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脚本的顶部:
来自IPython import embed
<$ c $> c> embed()
I use the following snippet to drop into a Python shell mid-program. This works fine, but I only get the standard console. Is there a way to do the same but using the IPython shell?
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()
解决方案The answer by f3lix is no longer valid it seems, I was able to find this however:
At the top of your python script:
from IPython import embed
Wherever you want to spin up a console:
embed()
这篇关于我可以在嵌入式交互式Python控制台中使用IPython吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文