【发布时间】:2018-09-08 13:40:48
【问题描述】:
如何在上一行打印 Jupyter 笔记本的状态?我想我正在寻找类似clear_output() 的东西,但只有一行。
示例代码:
from IPython.display import clear_output
import time
print('This is important info!')
for i in range(100):
print('Processing BIG data file {}'.format(i))
time.sleep(0.1)
clear_output(wait=True)
if i == 50:
print('Something bad happened on run {}. This needs to be visible at the end!'.format(i))
print('Done.')
当它运行时,它给出了覆盖前一个状态行的行为,但是标记为重要的两条线(带有感叹号和所有内容!)都丢失了。完成后,显示屏会显示:
Done.
应该说的是:
This is important info!
Something bad happened on run 50. This needs to be visible at the end!
Done.
This post 建议使用 clear_output() 然后重新打印所有内容。这似乎不切实际,因为我真正倾向于显示的数据量很大(很多图表,数据框,......)。
这是关于 clear_output() 的 two SO 链接。
有没有办法让这项工作不涉及重新打印所有内容?
【问题讨论】:
标签: python-3.x jupyter-notebook