【问题标题】:What is the difference between ipython TerminalInteractiveShell and InteractiveShell?ipython TerminalInteractiveShell 和 InteractiveShell 有什么区别?
【发布时间】:2021-01-15 21:28:30
【问题描述】:

ipython documentation 有一长串可配置选项。有些是针对TerminalInteractiveShell,有些是针对InteractiveShell。当我从命令行生成ipython_config.py 时,一些选项出现在文档中的一个和另一个中。这有什么押韵或理由吗?两者兼有的原因是什么?

【问题讨论】:

    标签: python configuration ipython


    【解决方案1】:

    查看文档中的list of modules,我们有

    IPython.core.application:IPython 的应用程序。

    IPython.core.interactiveshell:IPython 主类。

    IPython.terminal.ipapp: 命令行的 Application 对象 ipython 程序。

    IPython.terminal.interactiveshell: IPython 终端接口使用 prompt_toolkit

    InteractiveShell 是基本的 iPython shell 类,可以为不同的目的进行子类化。 TerminalInteractiveShell 就是这样一个特定的子类。它继承自InteractiveShell,是我们在命令行中键入“ipython”时运行的特定shell。

    一个可用于TerminalInteractiveShell不是基本InteractiveShell 的配置选项示例是confirm_exit。这似乎是合理的,因为“你真的要退出吗”这个问题只有在外壳内有人按下 Control-D 时才真正相关。

    实际上,如果您只是尝试配置命令行 ipython shell,则更改选项的InteractiveShellTerminalInteractiveShell 版本将起作用,因为TerminalInteractiveShell 继承了基类的选项。但是,只编辑更具体的TerminalInteractiveShell 更安全,因为基类仍在非终端情况下使用,并且更改其设置可能会导致出现意外行为。例如:

    希望这对您有所帮助!

    【讨论】:

      猜你喜欢
      • 2012-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-02
      • 2011-12-12
      • 2010-09-16
      相关资源
      最近更新 更多