首页 > 解决方案 > 如何在 tqdm 上打印进度条?

问题描述

如何在此 Python 代码的输出中获取进度条?我在这里尝试了一些答案,但没有什么对我有用

我在 Python 3.8.8 上使用“tqdm”库,在 CMD 上使用 Windows 10

这是我尝试过的:

from tqdm import tqdm

LIST = ['user1', 'user2', 'user3']
total = len(LIST)
bar = tqdm(total, desc='Processing')
for u in LIST:
    bar.update(LIST.index(u))

这是我不断得到的输出:

Processing: 0it [00:00, ?it/s]
Processing: 3it [00:00, 96.15it/s]

请问有什么帮助吗?

标签: pythonpython-3.xtqdm

解决方案


from tqdm import tqdm
import time

LIST = ['user1', 'user2', 'user3']

for u in tqdm(LIST):
    time.sleep(5)

推荐阅读