介绍一下python有趣的库-tqdm
生活随笔
收集整理的這篇文章主要介紹了
介绍一下python有趣的库-tqdm
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Tqdm 是 Python 進度條庫,可以在 Python 長循環(huán)中添加一個進度提示信息用法:tqdm(iterator)
方法1:
方法2:
import time from tqdm import trangefor i in trange(100):time.sleep(0.01)結(jié)果:
0%| | 0/100 [00:00<?, ?it/s]11%|█ | 11/100 [00:00<00:00, 100.00it/s]22%|██▏ | 22/100 [00:00<00:00, 100.00it/s]32%|███▏ | 32/100 [00:00<00:00, 100.00it/s]43%|████▎ | 43/100 [00:00<00:00, 100.00it/s]54%|█████▍ | 54/100 [00:00<00:00, 100.00it/s]64%|██████▍ | 64/100 [00:00<00:00, 99.11it/s] 74%|███████▍ | 74/100 [00:00<00:00, 99.37it/s]85%|████████▌ | 85/100 [00:00<00:00, 99.56it/s]95%|█████████▌| 95/100 [00:00<00:00, 99.69it/s] 100%|██████████| 100/100 [00:01<00:00, 99.70it/s]可以為進度條設(shè)置描述:
import time from tqdm import tqdmpbar = tqdm(["a", "b", "c", "d"]) for char in pbar: # 設(shè)置描述pbar.set_description("Processing %s" % char)time.sleep(1)結(jié)果:
0%| | 0/4 [00:00<?, ?it/s] Processing a: 25%|██▌ | 1/4 [00:01<00:03, 1.00it/s] Processing b: 50%|█████ | 2/4 [00:02<00:02, 1.00it/s] Processing c: 75%|███████▌ | 3/4 [00:03<00:01, 1.00it/s] Processing d: 100%|██████████| 4/4 [00:04<00:00, 1.00it/s] ''' 學習中遇到問題沒人解答?小編創(chuàng)建了一個Python學習交流QQ群:725638078 尋找有志同道合的小伙伴,互幫互助,群里還有不錯的視頻學習教程和PDF電子書! ''' 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)#方法2: pbar = tqdm(total=200) for i in range(20): pbar.update(10)time.sleep(0.1) # close() 不要也沒出問題? pbar.close()結(jié)果:
0%| | 0/200 [00:00<?, ?it/s]15%|█▌ | 30/200 [00:00<00:01, 150.00it/s]25%|██▌ | 50/200 [00:00<00:01, 130.43it/s]30%|███ | 60/200 [00:00<00:01, 119.52it/s]40%|████ | 80/200 [00:00<00:01, 112.91it/s]50%|█████ | 100/200 [00:00<00:00, 108.70it/s]55%|█████▌ | 110/200 [00:01<00:00, 105.93it/s]65%|██████▌ | 130/200 [00:01<00:00, 104.08it/s]75%|███████▌ | 150/200 [00:01<00:00, 102.82it/s]80%|████████ | 160/200 [00:01<00:00, 101.96it/s]85%|████████▌ | 170/200 [00:01<00:00, 96.38it/s] 90%|█████████ | 180/200 [00:01<00:00, 97.44it/s] 100%|██████████| 200/200 [00:01<00:00, 98.19it/s]總結(jié)
以上是生活随笔為你收集整理的介绍一下python有趣的库-tqdm的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python教程:序列的增量赋值
- 下一篇: python教程:深拷贝与浅拷贝的具体区