tqdm:Python 进度条
2018-12-16 18:45
453 查看
Tqdm 是 Python 进度条库,可以在 Python 长循环中添加一个进度提示信息。用户只需要封装任意的迭代器,是一个快速、扩展性强的进度条工具库。
用法:
tqdm(iterator)
- 代码地址:https://github.com/tqdm/tqdm
- 安装:
pip install tqdm
使用方法一: 传入可迭代对象
import time from tqdm import * for i in tqdm(range(1000)): time.sleep(.01) #进度条每0.1s前进一次,总时间为1000*0.1=100s
100%|██████████████████████████████████████████████████████████████████████████████| 1000/1000 [00:10<00:00, 93.97it/s]
使用方法二: trange
trange(i)是
tqdm(range(i))的简单写法
from tqdm import trange for i in trange(100): #do something pass
100%|█████████████████████████████████████████████████████████████████████████████| 100/100 [00:00<00:00, 99344.01it/s]
使用方法三: 可以为进度条设置描述
在
for循环外部初始化
tqdm,可以打印其他信息:
import time from tqdm import tqdm pbar = tqdm(["a", "b", "c", "d"]) for char in pbar: # 设置描述 pbar.set_description("Processing %s" % char) time.sleep(1)
Processing d: 100%|██████████████████████████████████████████████████████████████████████| 4/4 [00:04<00:00, 1.00s/it]
手动控制进度:
import time from tqdm import tqdm # 一共200个,每次更新10,一共更新20次 with tqdm(total=200) as pbar: for i in range(20): pbar.update(10) time.sleep(0.1)
100%|████████████████████████████████████████████████████████████████████████████████| 200/200 [00:01<00:00, 98.87it/s]
tqdm 的 write 方法
bar = trange(10) for i in bar: time.sleep(0.1) if not (i % 3): tqdm.write("Done task %i" % i)
Done task 0 0%| | 0/10 [00:10<?, ?it/s] 0%| | 0/10 [00:00<?, ?it/s] 10%|████████▎ | 1/10 [00:00<00:01, 8.77it/s] 20%|████████████████▌ | 2/10 [00:00<00:00, 9.22it/s] Done task 3 0%| | 0/10 [00:10<?, ?it/s] 30%|████████████████████████▉ | 3/10 [00:00<00:01, 6.91it/s] 40%|█████████████████████████████████▏ | 4/10 [00:00<00:00, 9.17it/s] 50%|█████████████████████████████████████████▌ | 5/10 [00:00<00:00, 9.28it/s] Done task 6 0%| | 0/10 [00:10<?, ?it/s] 60%|█████████████████████████████████████████████████▊ | 6/10 [00:00<00:00, 7.97it/s] 70%|██████████████████████████████████████████████████████████ | 7/10 [00:00<00:00, 9.25it/s] 80%|██████████████████████████████████████████████████████████████████▍ | 8/10 [00:00<00:00, 9.31it/s] Done task 9 0%| | 0/10 [00:11<?, ?it/s] 90%|██████████████████████████████████████████████████████████████████████████▋ | 9/10 [00:01<00:00, 8.37it/s] 100%|██████████████████████████████████████████████████████████████████████████████████| 10/10 [00:01<00:00, 9.28it/s]
相关文章推荐
- python之Tqdm库实现进度条功能
- python3.6+anaconda5安装tqdm(Python进度条)成功图文教程
- 180207 python tqdm进度条的使用
- tqdm==>python可扩展进度条
- 对python GUI实现完美进度条的示例详解
- Python实现采用进度条实时显示处理进度的方法
- Python案例-开发之路-进度条实现
- Python实现控制台中的进度条功能代码
- Python在Console下显示文本进度条的方法
- Python进度条实时显示处理进度的示例代码
- Python实现控制台中的进度条
- tqdm==>python可扩展进度条
- Python打印进度条
- tqdm【Python进度条】
- python实现socket上传下载文件-进度条显示
- Python实现屏幕输出进度条的方法
- Python实现控制台中的进度条
- python的进度条实现
- Python进度条小实例
- python实现socket上传下载文件-进度条显示