Python 进度条神器 tqdm

安装

1
pip install tqdm

演示:

1
2
3
from tqdm import tqdm
for i in tqdm(range(10000)):
pass

用法

1
2
3
4
from tqdm import tqdm
text = ""
for char in tqdm(["a", "b", "c", "d"]):
text = text + char
1
2
3
from tqdm import trange
for i in trange(100):
pass
1
2
3
4
from tqdm import tqdm
pbar = tqdm(["a", "b", "c", "d"])
for char in pbar:
pbar.set_description("Processing %s" % char)
1
2
3
4
from tqdm import tqdm
with tqdm(total=100) as pbar:
for i in range(10):
pbar.update(10)
1
2
3
4
5
from tqdm import tqdm
pbar = tqdm(total=100)
for i in range(10):
pbar.update(10)
pbar.close()
1
2