【Python】记录九:显示进度条工具tqdm简介

python中有很多丰富的第三方库,tqdm就是一种非常简单又实用的工具,它能够显示当前程序的执行进度,这个功能非常适合于长时间执行程序时使用。

关于tqdm这个有点难记的名字的由来,作者在github上是这么解释的:

tqdm means “progress” in Arabic (taqadum, تقدّم) and is an abbreviation for “I love you so much” in Spanish (te quiero demasiado).

西班牙语中的<我是如此爱你>~

基本用法

它的用法很简单,一般在循环操作中使用:

from time import sleep
from tqdm import tqdm

for i in tqdm(range(1000)):
    sleep(0.01)

执行代码的结果是:

  0%|          | 0/1000 [00:00<?, ?it/s]
  1%|          | 10/1000 [00:00<00:10, 91.98it/s]
  2%|| 19/1000 [00:00<00:10, 90.34it/s]
  3%|| 28/1000 [00:00<00:10, 89.22it/s]
  4%|| 37/1000 [00:00<00:10, 88.62it/s]
  5%|| 46/1000 [00:00<00:10, 88.05it/s]
  6%|| 55/1000 [00:00<00:10, 88.16it/s]
  6%|| 64/1000 [00:00<00:10, 88.03it/s]
  7%|| 73/1000 [00:00<00:10, 87.91it/s]
  8%|| 82/1000 [00:00<00:10, 88.07it/s]
  9%|| 91/1000 [00:01<00:10, 88.16it/s]
 10%|| 100/1000 [00:01<00:10, 87.99it/s]
 11%|| 109/1000 [00:01<00:10, 87.88it/s]
 12%|█▏        | 118/1000 [00:01<00:10, 87.79it/s]
 13%|█▎        | 127/1000 [00:01<00:09, 87.98it/s]
 14%|█▎        | 136/1000 [00:01<00:09, 87.86it/s]
 14%|█▍        | 145/1000 [00:01<00:09, 87.72it/s]
 15%|█▌        | 154/1000 [00:01<00:09, 87.60it/s]
 16%|█▋        | 163/1000 [00:01<00:09, 87.55it/s]
 17%|█▋        | 172/1000 [00:01<00:09, 87.56it/s]
 18%|█▊        | 181/1000 [00:02<00:09, 87.57it/s]
 19%|█▉        | 190/1000 [00:02<00:09, 87.57it/s]
 20%|█▉        | 199/1000 [00:02<00:09, 87.58it/s]
 21%|██        | 208/1000 [00:02<00:09, 87.59it/s]
 22%|██▏       | 217/1000 [00:02<00:08, 87.76it/s]
 23%|██▎       | 226/1000 [00:02<00:08, 88.26it/s]
 24%|██▎       | 235/1000 [00:02<00:08, 88.06it/s]
 24%|██▍       | 244/1000 [00:02<00:08, 87.91it/s]
 25%|██▌       | 253/1000 [00:02<00:08, 87.55it/s]
 26%|██▌       | 262/1000 [00:02<00:08, 87.81it/s]
 27%|██▋       | 271/1000 [00:03<00:08, 88.24it/s]
 28%|██▊       | 280/1000 [00:03<00:08, 88.41it/s]
 29%|██▉       | 289/1000 [00:03<00:08, 88.33it/s]
 30%|██▉       | 298/1000 [00:03<00:07, 88.30it/s]
 31%|███       | 307/1000 [00:03<00:07, 88.28it/s]
 32%|███▏      | 316/1000 [00:03<00:07, 88.46it/s]
 32%|███▎      | 325/1000 [00:03<00:07, 87.93it/s]
 33%|███▎      | 334/1000 [00:03<00:07, 87.68it/s]
 34%|███▍      | 343/1000 [00:03<00:07, 87.87it/s]
 35%|███▌      | 352/1000 [00:04<00:07, 87.70it/s]
 36%|███▌      | 361/1000 [00:04<00:07, 87.87it/s]
 37%|███▋      | 370/1000 [00:04<00:07, 87.80it/s]
 38%|███▊      | 379/1000 [00:04<00:07, 88.12it/s]
 39%|███▉      | 388/1000 [00:04<00:06, 88.35it/s]
 40%|███▉      | 397/1000 [00:04<00:06, 88.28it/s]
 41%|████      | 406/1000 [00:04<00:06, 88.53it/s]
 42%|████▏     | 415/1000 [00:04<00:06, 88.25it/s]
 42%|████▏     | 424/1000 [00:04<00:06, 87.80it/s]
 43%|████▎     | 433/1000 [00:04<00:06, 87.75it/s]
 44%|████▍     | 442/1000 [00:05<00:06, 87.45it/s]
 45%|████▌     | 451/1000 [00:05<00:06, 87.25it/s]
 46%|████▌     | 460/1000 [00:05<00:06, 87.10it/s]
 47%|████▋     | 469/1000 [00:05<00:06, 87.00it/s]
 48%|████▊     | 478/1000 [00:05<00:05, 87.18it/s]
 49%|████▊     | 487/1000 [00:05<00:05, 87.82it/s]
 50%|████▉     | 496/1000 [00:05<00:05, 87.76it/s]
 50%|█████     | 505/1000 [00:05<00:05, 87.46it/s]
 51%|█████▏    | 514/1000 [00:05<00:05, 87.39it/s]
 52%|█████▏    | 523/1000 [00:05<00:05, 87.38it/s]
 53%|█████▎    | 532/1000 [00:06<00:05, 87.63it/s]
 54%|█████▍    | 541/1000 [00:06<00:05, 87.55it/s]
 55%|█████▌    | 550/1000 [00:06<00:05, 87.50it/s]
 56%|█████▌    | 559/1000 [00:06<00:05, 87.49it/s]
 57%|█████▋    | 568/1000 [00:06<00:04, 87.71it/s]
 58%|█████▊    | 577/1000 [00:06<00:04, 87.86it/s]
 59%|█████▊    | 586/1000 [00:06<00:04, 87.47it/s]
 60%|█████▉    | 595/1000 [00:06<00:04, 87.71it/s]
 60%|██████    | 604/1000 [00:06<00:04, 87.86it/s]
 61%|██████▏   | 613/1000 [00:06<00:04, 87.96it/s]
 62%|██████▏   | 622/1000 [00:07<00:04, 88.04it/s]
 63%|██████▎   | 631/1000 [00:07<00:04, 87.87it/s]
 64%|██████▍   | 640/1000 [00:07<00:04, 88.23it/s]
 65%|██████▍   | 649/1000 [00:07<00:03, 88.24it/s]
 66%|██████▌   | 658/1000 [00:07<00:03, 88.23it/s]
 67%|██████▋   | 667/1000 [00:07<00:03, 87.70it/s]
 68%|██████▊   | 676/1000 [00:07<00:03, 87.88it/s]
 68%|██████▊   | 685/1000 [00:07<00:03, 87.41it/s]
 69%|██████▉   | 694/1000 [00:07<00:03, 87.22it/s]
 70%|███████   | 703/1000 [00:08<00:03, 87.34it/s]
 71%|███████   | 712/1000 [00:08<00:03, 87.42it/s]
 72%|███████▏  | 721/1000 [00:08<00:03, 86.97it/s]
 73%|███████▎  | 730/1000 [00:08<00:03, 87.16it/s]
 74%|███████▍  | 739/1000 [00:08<00:02, 87.30it/s]
 75%|███████▍  | 748/1000 [00:08<00:02, 86.89it/s]
 76%|███████▌  | 757/1000 [00:08<00:02, 87.10it/s]
 77%|███████▋  | 766/1000 [00:08<00:02, 87.51it/s]
 78%|███████▊  | 775/1000 [00:08<00:02, 87.54it/s]
 78%|███████▊  | 784/1000 [00:08<00:02, 87.56it/s]
 79%|███████▉  | 793/1000 [00:09<00:02, 87.58it/s]
 80%|████████  | 802/1000 [00:09<00:02, 87.63it/s]
 81%|████████  | 811/1000 [00:09<00:02, 87.91it/s]
 82%|████████▏ | 820/1000 [00:09<00:02, 87.99it/s]
 83%|████████▎ | 829/1000 [00:09<00:01, 88.06it/s]
 84%|████████▍ | 838/1000 [00:09<00:01, 88.37it/s]
 85%|████████▍ | 847/1000 [00:09<00:01, 88.85it/s]
 86%|████████▌ | 856/1000 [00:09<00:01, 88.48it/s]
 86%|████████▋ | 865/1000 [00:09<00:01, 88.21it/s]
 87%|████████▋ | 874/1000 [00:09<00:01, 88.03it/s]
 88%|████████▊ | 883/1000 [00:10<00:01, 88.16it/s]
 89%|████████▉ | 892/1000 [00:10<00:01, 88.26it/s]
 90%|█████████ | 901/1000 [00:10<00:01, 88.32it/s]
 91%|█████████ | 910/1000 [00:10<00:01, 88.37it/s]
 92%|█████████▏| 919/1000 [00:10<00:00, 88.66it/s]
 93%|█████████▎| 928/1000 [00:10<00:00, 88.60it/s]
 94%|█████████▎| 937/1000 [00:10<00:00, 88.56it/s]
 95%|█████████▍| 946/1000 [00:10<00:00, 88.02it/s]
 96%|█████████▌| 955/1000 [00:10<00:00, 88.15it/s]
 96%|█████████▋| 964/1000 [00:10<00:00, 88.40it/s]
 97%|█████████▋| 973/1000 [00:11<00:00, 88.07it/s]
 98%|█████████▊| 982/1000 [00:11<00:00, 88.14it/s]
 99%|█████████▉| 991/1000 [00:11<00:00, 87.85it/s]
100%|██████████| 1000/1000 [00:11<00:00, 87.78it/s]

参考

两个惊艳的python库:tqdm和retry - mdumpling - 博客园
https://www.cnblogs.com/mdumpling/p/8016741.html

tqdm developers
https://github.com/tqdm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值