【问题标题】:Can I use IPython in an embedded interactive Python console?我可以在嵌入式交互式 Python 控制台中使用 IPython 吗?
【发布时间】:2009-01-31 22:29:21
【问题描述】:

我使用以下 sn-p 进入 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()

【问题讨论】:

  • 您能否将 Dereck 的答案标记为当前最新?

标签: python console


【解决方案1】:

f3lix 的答案似乎不再有效,但是我能够找到这个:

在 Python 脚本的顶部:

from IPython import embed

无论您想在哪里启动控制台:

embed()

【讨论】:

    【解决方案2】:

    Embedding IPython 可能对你来说很有趣。

    在您的应用中运行 IPython 的最少代码:

    from IPython.Shell import IPShellEmbed
    ipshell = IPShellEmbed()
    ipshell() # this call anywhere in your program will start IPython 
    

    【讨论】:

    • 见下文,现在可以使用来自 IPython 的嵌入函数。
    猜你喜欢
    • 1970-01-01
    • 2019-08-17
    • 2011-07-24
    • 1970-01-01
    • 2013-09-28
    • 2014-08-29
    • 2014-10-13
    • 2017-08-24
    • 1970-01-01
    相关资源
    最近更新 更多