首页 > 解决方案 > 带有文件大小的 Python TQDM 缩放进度条

问题描述

我使用 python 模块 tqdm 来(例如:)迭代应该打开的文件列表。通常显示的进度会随着文件的数量而变化。在现实生活中,进度与文件大小(或有时它的平方)而不是数字无关。

我只找到了使用更新方法的解决方案。我想问是否有更好的方法。特别是关闭进度条后有一个小错误。

from tqdm.notebook import tqdm
from numpy import rint, sum
pbar = tqdm(file_paths, total = int(rint(sum(file_sizes)/1024/1024)), unit='mb')
for x in pbar:
        pass  # file open the file and do some calculation
        pbar.update(int(rint(x.stat().st_size//1024/1024)))  # convert bytes into mbytes and round to nearest integer
pbar.close()

我想问一下,是否有:

标签: pythontqdm

解决方案


推荐阅读