tqdm
with tqdm(total=len(a), desc='test_round', unit='round') as pbar:
for i in a:
# print(i)
pbar.update(1)
pbar.set_postfix({"finished": f"{i+1}"})
# pbar.set_postfix_str(f"finished:{i+1}")
time.sleep(1)
>>> test_round: 100%|██████████| 10/10 [00:10<00:00, 1.01s/round, finished=10]
- 写法二
缺点:暂时没找到可以(像方法一中的set_postfix
)动态更新自定义信息的办法
for i in tqdm(a, desc='test_round', unit='round'):
time.sleep(1)
>>> test_round: 100%|██████████| 10/10 [00:10<00:00, 1.01s/round]
- 写法三
效果同写法一,但少一层缩进
缺点:要手动删除 tqdm()对象
tmp_pbar = tqdm(a, desc='test_round', unit='round')
for i in tmp_pbar:
tmp_pbar.set_postfix_str(f"finished:{i+1}")
time.sleep(1)
del tmp_pbar