python - 访问 tqdm desc 关键字参数中 for 循环的成员

标签 python progress-bar tqdm

是否可以在进度条前缀的 for 循环中访问当前项目(desc 关键字参数)。也就是说,要让这样的事情发挥作用:

from tqdm import tqdm
for x in tqdm(['a' ,'b', 'c'], desc='item {}'.format(x)):
    pass

该代码在 for 循环行产生一个 NameError: name 'x' is not Defined。是否可以创建一个进度条,其中前缀在 for 循环中用 x 更新。

item a: 100%|███████████████████████████████████████| 1/3 [00:00<?, ?it/s]
item b: 100%|███████████████████████████████████████| 2/3 [00:00<?, ?it/s]
item c: 100%|███████████████████████████████████████| 3/3 [00:00<?, ?it/s]

最佳答案

这样的东西有用吗?

pbar = tqdm(["a", "b", "c"])
for x in pbar:
    pbar.set_description('item {}'.format(x))

关于python - 访问 tqdm desc 关键字参数中 for 循环的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60896231/

相关文章:

python - 如何匹配 python 正则表达式中的零个或多个括号

python - 使用 NLTK 生成字典以将推文分类为预定义的类别

python - 使用 colorama 更改 Python 输入的文本颜色

javascript - JavaScript 进度条无限加载的问题

php - 使用 ajax 的 php 和 javascript 是否可以使用进度条

python - tqdm显示的 'speed'是瞬时速度还是平均速度?

python - OpenCV-在检测到Canny边缘后找到血管轮廓

C# 如何获取下载文件的大小以显示进度条百分比

python - pandas .corr() 方法的进度条

Python 进度条 tqdm