python - 是否可以在 Jupyter Notebook 单元中在显示多个输出和单个输出之间来回切换?

标签 python ipython jupyter-notebook jupyter

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

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

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

我尝试发行

    InteractiveShell.ast_node_interactivity = "last_expr"

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

最佳答案

您可以在 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,并且解析器有点挑剔,您可能不需要周围有空格=

享受吧!

关于python - 是否可以在 Jupyter Notebook 单元中在显示多个输出和单个输出之间来回切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47436322/

相关文章:

python - 如何判断是否从 jupyter notebook 调用了一个函数?

ipython - 正确关闭 PySpark 笔记本

python - 尝试在 Python 3 中拆分字符串,得到 'str' 不支持缓冲区接口(interface)

python - 在Python中导入颜色科学模块时出现"TypeError"

python - 使用 Django 1.5 和 IPython 获取 NameError

python - 为什么matplotlib默认不保存整图?

apache-spark - Scala 的 Apache Toree 语法高亮

python - 使用多列连接 Pandas 数据框

Python 使用列表时输入错误

python - IPython 上基于 sum() 的执行时间差