tqdm:两级进度条

from tqdm import tqdm
import time


def ones(epoch, end):
    count = 100
    bar = tqdm(total=count, leave=(epoch == end), desc="train", position=1)
    for _ in range(count):
        time.sleep(0.01)
        bar.set_postfix({
    
    "index": index, "epoch": epoch, "number": index ** 5 / 50000})
        bar.update()
    bar.close()


def main(start=0, end=100):
    bar = tqdm(range(start, end), dynamic_ncols=True, leave=True, desc="Epochs")

    for epoch in range(start, end):
        ones(epoch + 1, end)
        bar.update()


if __name__ == '__main__':
    main(0, 100)

在终端显示效果
在这里插入图片描述

如果是在pycharm中运行,会出现金字塔的效果,在终端中不会,只会显示两行(上图所示),是很方便的,也可以打印
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_50727642/article/details/126884650
今日推荐