简体   繁体   English

如何在每一步在 Jupyter Notebook 中显示 output?

[英]How to display output in Jupyter Notebook at each step?

I have this problem that the IPython in jupyter notebook does not print the results interactively like command prompt or python regular shell.我有这个问题,jupyter notebook 中的 IPython 不会像命令提示符或 python 常规 shell 那样交互打印结果。 And by printing interactively I mean, it does not show the output at each step and for example, shows the output of a code block like this, at the end of the execution.通过交互打印,我的意思是,它不会在每个步骤中显示 output,例如,在执行结束时显示这样的代码块的 output。

for i in raange(100):
    print(i)

I have never worked with jupyter notebook before, at least not locally, and when I did use it, it was on the GoogleColab.我以前从未使用过 jupyter notebook,至少不是在本地使用过,当我使用它时,它在 GoogleColab 上。 In GoogleColab there is no problem like what I said above.在 GoogleColab 中没有我上面所说的问题。

So can anyone help me or at least tell me that have they experienced this problem too or is it just me who has this problem?那么任何人都可以帮助我或至少告诉我他们是否也遇到过这个问题,或者只有我有这个问题?

The solution shown in the question you linked works for me, just execute您链接的问题中显示的解决方案对我有用,只需执行

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

in the first cell, and then it will output each line's output as follows:在第一个单元格中,然后它将 output 每一行的 output 如下:

a=5
a
a
a *2

>>> 5
>>> 5
>>> 10

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM