tqdm.使用多个酒吧 [英] tqdm. Using multiple bars

查看:109
本文介绍了tqdm.使用多个酒吧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有两个独立的进度条.

I would like to have two independent progress bars.

这是一个最小的示例,如果我使用两个小节,它们将无法正确更新.而是创建新的条形.

This is a minimal example where if I use two bars they are not updated properly. Instead new bars are created.

import time
from tqdm import *

pbar1 = tqdm(total=100)
pbar2 = tqdm(total=200)

for i in range(10):
    pbar1.update(10)
    pbar2.update(20)
    time.sleep(1)

运行示例时.我得到类似的东西:

When running the example. I get something like:

  0%|          | 0/100 [00:00<?, ?it/s]
 20%|██        | 20/100 [00:01<00:04, 19.97it/s]
 30%|███       | 30/100 [00:02<00:04, 15.36it/s]
 40%|████      | 40/100 [00:03<00:04, 13.23it/s]
 50%|█████     | 50/100 [00:04<00:04, 12.05it/s]
 60%|██████    | 60/100 [00:05<00:03, 11.35it/s]
 70%|███████   | 70/100 [00:06<00:02, 10.90it/s]
 80%|████████  | 80/100 [00:07<00:01, 10.61it/s]
 90%|█████████ | 90/100 [00:08<00:00, 10.42it/s]
100%|██████████| 100/100 [00:09<00:00, 10.28it/s]
100%|██████████| 200/200 [00:09<00:00, 20.57it/s]

如图所示,更新无法正常进行,并添加了新的条形图. 有可能有两个独立的酒吧可以正确更新吗?

As shown, updating does not work properly and adds new bars. Is it possible to have two independent bars that update properly?

推荐答案

初始化小节时尝试使用position参数:

Try using the position parameter when initialising the bars:

pbar1 = tqdm(total=100, position=1)
pbar2 = tqdm(total=200, position=0)

tqdm GitHub页面:

position:int,可选

position : int, optional

指定打印此栏的行偏移量(从0开始).如果未指定,则自动显示.一次管理多个条很有用(例如,从线程).

Specify the line offset to print this bar (starting from 0) Automatic if unspecified. Useful to manage multiple bars at once (eg, from threads).

这篇关于tqdm.使用多个酒吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆