首页 > 解决方案 > 每次迭代后清除 tqdm 进度的输出

问题描述

我正在使用 colab notebbok 编写带有 tqdm 进度条的嵌套循环。在主循环中,我想在每次迭代后清除输出。

我目前的尝试:

from tqdm.notebook import trange
import sys
from time import sleep

def something(x):
  for i in trange(x):
    x**2

x = 5 

for i in range(x):
  tqdm.write('------------------------- Iteration %d -------------------------' % (i))
  tqdm.write('first iteration:')
  something(x)
  tqdm.write('second iteration:')
  something(x)
  sleep(.3)
  sys.stdout.flush()

但是每次迭代我仍然会得到新的行,是否有任何选项可以在主循环中的每次迭代后清除输出?

标签: pythonprogress-bargoogle-colaboratorytqdm

解决方案


推荐阅读