原文链接: https://mp.weixin.qq.com/s/gRpNq15bX4OgpiY5NNO_OQ
效果展示:
基础使用
导入 alive-progress 库
from alive_progress import alive_bar
import time
使用 with 语句创建一个进度条
with alive_bar(100) as bar: # 给 alive_bar 传入进度条总数目(这里是 100)
for item in range(100):
# 等待 1s
time.sleep(.1)
#更新进度条,进度 +1
bar()
注:
1.如果无法正常显示动画则尝试在 alive_bar 中加上force_tty=True参数。
自动迭代
在最新版中它也支持向tqdm的调用方式
import time
from alive_progress import alive_it
for item in alive_it(range(10),force_tty=True): # <<-- wrapped items
time.sleep(1) # process each item