介绍
实现进度条
在长循环中添加一个进度提示信息,只需要封装任意的迭代器 tqdm(iterator)
安装
pip install tqdm
例子
from tqdm import tqdm
import time
l=range(100)
for i in tqdm(l):
time.sleep(0.1)
修改提示信息
pbar = tqdm(["a", "b", "c", "d"])
for char in pbar:
pbar.set_description("当前字符: %s" % char)
time.sleep(1)
显示中文会多出一行,英文则不会
手动更新
with tqdm(total=100) as pbar:
for i in range(10):
pbar.update(10)
或者
pbar = tqdm(total=100)
for i in range(10):
pbar.update(10)
pbar.close()
更多用法见:
https://blog.csdn.net/langb2014/article/details/54798823

