安装tqdm库:
pip install tqdm
一,显示进度条
import tqdm
for i in tqdm(range(100)):
pass
100%|██████████| 100/100 [00:00<?, ?it/s]
Process finished with exit code 0
二,进度条跑起来
import time
import tqdm
for i in tqdm(range(1000)):
time.sleep(0.0001)
100%|██████████| 1000/1000 [00:01<00:00, 521.68it/s]
Process finished with exit code 0
三,手动更新进度条
import tqdm
bar = tqdm(total=10000000000)
for i in range(100000000):
value = int(i * 0.000001 + 0.5) * 2
bar.update(value) #迭代值value不超出total
100%|██████████| 100000000/100000000 [00:00<00:00, 105322890.20it/s]
Process finished with exit code 0