python - 带有文件大小的 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()
我想问一下,是否有:
- a) 是一种将权重添加到构造函数而不是调用更新方法的方法
- b)进度条有更好的(内置)舍入方法
- c)修复错误:这是在关闭进度条之后而不是当前权重(但显示了被迭代的列表的长度)。
解决方案
推荐阅读
- c# - 基于 mrp 获得折扣价格的逻辑
- ruby-on-rails - Rails - active_link_to wrap 选项卡不起作用
- javafx - JavaFX 将操作设置为另一个类中的按钮
- composer-php - Laravel Envoyer 部署挂钩安装 Composer 依赖项失败
- jenkins - 在詹金斯管道中的多行shell脚本中访问项目参数
- wso2 - WINDOWS 10 上的 WSO2 分析编辑器
- python - 从 DateTimeIndex 中截断毫秒
- mysql - SQL INSERT INTO 从一张表插入两张表
- linux - tcpdump 不显示 Wireshark 看到的数据包
- mysql - 从 MYSQL 用户主机中删除附加的网络名称