【发布时间】:2021-08-17 08:05:37
【问题描述】:
我在 Jupyter 笔记本中有一个循环,除了该循环之外,我还想在该循环内定期打印。例如
from tqdm.notebook import tqdm
running = 0
for itt in tqdm(range(40)):
running = running + itt
if itt % 10 == 0:
print(running/10)
除了tqdm吧,我得到
0.0
5.5
21.0
46.5
我希望每个打印语句都替换之前的语句。
所以到最后我应该只看到46.5
在打印语句中,我尝试了使用 end='/r' 和 flush=True 的组合,但它们要么继续打印新行,要么不打印任何行。我也试过tqdm.write,但这会导致“TypeError:'float' object is not subscriptable
"
【问题讨论】:
标签: python jupyter-notebook jupyter jupyter-lab tqdm