Python 错误 'ZipFile' object has no attribute 'file_size' 解决方法
这个错误是因为 Python 版本不同导致的。在 Python 2.x 版本中,ZipFile 类具有 'file_size' 属性,但在 Python 3.x 版本中,ZipFile 类已更新并删除了 'file_size' 属性。因此,如果你在 Python 3.x 版本中使用 ZipFile 类的 'file_size' 属性,则会出现这个错误。
解决这个问题的方法是,在 Python 3.x 版本中,使用 ZipFile 类的 getinfo() 方法来获取压缩文件的大小。例如:
import zipfile
with zipfile.ZipFile('example.zip', 'r') as zip_ref:
file_info = zip_ref.getinfo('example.txt')
print(file_info.file_size)
这将打印出 'example.txt' 文件在 'example.zip' 压缩文件中的大小。
原文地址: https://www.cveoy.top/t/topic/mWVT 著作权归作者所有。请勿转载和采集!