alive-progress是一个有着非常绚丽动画的实时进度条库。相比tqdmpython-prompt-toolkit的Progress bars等进度条库,有着更佳好看的动画界面,让人欲罢不能。

1
2
3
4
5
6
7
8
from alive_progress import alive_bar
import time

for x in 1000, 1500, 700, 0:
with alive_bar(x) as bar:
for i in range(1000):
time.sleep(.005)
bar()

** 输入结果

1
2
3
4
|████████████████████████████████████████| 1000/1000 [100%] in 5.8s (171.62/s)
|██████████████████████████▋⚠︎ | (!) 1000/1500 [67%] in 5.8s (172.62/s)
|████████████████████████████████████████✗︎ (!) 1000/700 [143%] in 5.8s (172.06/s)
|████████████████████████████████████████| 1000 in 5.8s (172.45/s)
1
2
3
4
with alive_bar(total) as bar:  # declare your expected total
for item in items: # <<-- your original loop
print(item) # process each item
bar() # call `bar()` at the end