本文介绍了在 Jupyter Notebook 的 for 循环中刷新输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 Jupyter 笔记本上的迭代中打印出 i
并将其刷新.在下一次迭代之后,我将打印下一个 i
.我尝试了这个问题和这个问题,但是,它只是打印出0123...9代码> 没有为我刷新输出.这是我的工作代码:
I want to print out
i
in my iteration on Jupyter notebook and flush it out. After the next iteration, I'll print the next i
. I tried solutions from this question and this question, however, it just print out 0123...9
without flushing the output for me. Here is my working code:
import sys
import time
for i in range(10):
sys.stdout.write(str(i)) # or print(i, flush=True) ?
time.sleep(0.5)
sys.stdout.flush()
这些是我的设置:ipython 5.1、python 3.6.也许,我在之前的解决方案中遗漏了什么?
these are my setup: ipython 5.1, python 3.6. Maybe, I missed something in the previous solution?
推荐答案
#Try this:
import sys
import time
for i in range (10):
sys.stdout.write('
'+str(i))
time.sleep(0.5)
这篇关于在 Jupyter Notebook 的 for 循环中刷新输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!