TqdmPython 进度条

联合创作 · 2023-09-28 17:55

Tqdm 是一个快速,可扩展的Python进度条,可以在 Python 长循环中添加一个进度提示信息,用户只需要封装任意的迭代器 tqdm(iterator)。

安装:

  • 最新的PyPI稳定版

pip install tqdm
  • 在github上最新的开发版本

pip install -e git+https://github.com/tqdm/tqdm.git@master#egg=tqdm

用法:

  • 基于可迭代

1.总结各地可迭代的tqdm():

text = ""
for char in tqdm(["a", "b", "c", "d"]):
    text = text + char

2.trange(i)是tqdm(i)的一个特殊实例:

for i in trange(100): 
   pass

3.对于实例之外的循环允许对tqdm()手动控制:

pbar = tqdm(["a", "b", "c", "d"])
for char in pbar:
    pbar.set_description("Processing %s" % char)
浏览 7
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报