是否可以在进度条前缀的 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/