tqdm derives from the Arabic word taqaddum (تقدّم) which can mean “progress,” and is an abbreviation for “I love you so much” in Spanish (te quiero demasiado).
Instantly make your loops show a smart progress meter - just wrap any iterable with tqdm(iterable), and you’re done!
1、代码示例1:
python">from tqdm import tqdm
from time import sleep
text = ""
for char in tqdm(["a", "b", "c", "d"]):
sleep(0.25)
text = text + char
100%|██████████| 4/4 [00:01<00:00, 3.83it/s]
2、示例代码2:
python">pbar = tqdm(["a", "b", "c", "d"])
for char in pbar:
sleep(0.25)
pbar.set_description("Processing %s" % char)
Processing d: 100%|██████████| 4/4 [00:01<00:00, 3.82it/s]
3、示例代码3:
python">from tqdm import trange
for i in trange(100):
sleep(0.01)
100%|██████████| 100/100 [00:01<00:00, 64.20it/s]
4、示例代码4:
python">with tqdm(total=100) as pbar:
for i in range(10):
sleep(0.1)
pbar.update(10)
100%|██████████| 100/100 [00:01<00:00, 91.19it/s]