代码之家  ›  专栏  ›  技术社区  ›  chinex

是否可以在Jupyter笔记本电池中显示多个输出和单个输出之间来回切换?

  •  1
  • chinex  · 技术社区  · 7 年前

    要在我使用的单元格中显示多个输出,

        from IPython.core.interactiveshell import InteractiveShell
        InteractiveShell.ast_node_interactivity = "all"
    

    但是,如果我有一个单元格,我只想从中获得一个输出,我该如何切换回同一个笔记本呢。

    我试过发行

        InteractiveShell.ast_node_interactivity = "last_expr"
    

    在我想要一个输出的单元格中,但它似乎不起作用。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Matt    7 年前

    您可以在IPython中发布以下内容(终端、笔记本等)提示:

    %config
    

    它将告诉您可以配置哪个对象:

    Available objects for config:
     AliasManager
     DisplayFormatter
     HistoryManager
     IPCompleter
     IPKernelApp
     InlineBackend
     LoggingMagics
     MagicsManager
     PrefilterManager
     ScriptMagics
     StoreMagics
     ZMQInteractiveShell
    

    请注意 ZMQInteractiveShell TerminalInteractiveShell 在终端中。在我们的例子中,也就是说,我们对配置感兴趣的是什么 config 更多信息:

    %config ZMQInteractiveShell
    
    ZMQInteractiveShell options
    -------------------------
    ZMQInteractiveShell.ast_node_interactivity=<Enum>
        Current: 'last_expr'
        Choices: ['all', 'last', 'last_expr', 'none', 'last_expr_or_assign']
        'all', 'last', 'last_expr' or 'none', 'last_expr_or_assign' specifying which
        nodes should be run interactively (displaying output from expressions).
    ZMQInteractiveShell.ast_transformers=<List>
        Current: []
    

    哦那么让我们分配:

    %config InteractiveShell.ast_node_interactivity="last_expr"
    

    你已经准备好了,而且你已经学会了如何潜入IPython配置系统。

    注意,它可能不适用于所有配置选项(如果是这样,请打开错误报告),但它应该适用于 last_node_interactivity ,并且解析器有点挑剔,您可能需要在 = .

    享受