ZIP_STORED和ZIP_LZMA没有compresslevel参数!

在使用py的zipfile库进行压缩的时候,有这么一个函数:

复制代码
def write(self, filename, arcname=None,
              compress_type=None, compresslevel=None):

一般我们在压缩文件进去的时候都是用这个函数的;

对于compresslevel这个函数,它是用来指明压缩等级的;

我使用ZIP_LZMA模式进行压缩,并且尝试指定compresslevel;神奇的事情出现了:不管怎么调level,压缩出来的大小都不会有改变;

把write函数让ai解释,ai信誓旦旦说这个参数接受0-9;

不信邪的我查了zipfile里面的参数介绍,原文如下:

复制代码
compresslevel: None (default for the given compression type) or an integer
                   specifying the level to pass to the compressor.
                   When using ZIP_STORED or ZIP_LZMA this keyword has no effect.
                   When using ZIP_DEFLATED integers 0 through 9 are accepted.
                   When using ZIP_BZIP2 integers 1 through 9 are accepted.

所以,ZIP_STORED和ZIP_LZMA接受的compresslevel参数根本就没有意义!

这也很好理解,store本身就不压缩,就是直白储存,你指定level自然没有意义;我现在用的这个ZIP_LZMA模式本身就是一个高压缩比的算法,再指定level,那不就是玩呢

再吃了一个教训:细致的问题多看源码,少问ai

相关推荐
开开心心_Every16 分钟前
手机隐私数据彻底删除工具:回收或弃用手机前防数据恢复
android·windows·python·搜索引擎·智能手机·pdf·音视频
Nina_71736 分钟前
Day 14 训练
python
zx431 小时前
聚类后的分析:推断簇的类型
人工智能·python·机器学习·聚类
RunsenLIu1 小时前
基于Django实现的篮球论坛管理系统
后端·python·django
COOCC12 小时前
PyTorch 实战:从 0 开始搭建 Transformer
人工智能·pytorch·python·深度学习·算法·机器学习·transformer
sword devil9002 小时前
加速项目落地(Trae编辑器)
python·编辑器·辅助开发
985小水博一枚呀3 小时前
【EI会议推荐】2025年6月智启未来:通信导航、 机器学习、半导体与AI、数字创新领域国际研讨会总结!
人工智能·python·深度学习·机器学习
www_pp_4 小时前
# 创建一个功能完备的计算器应用:使用PyQt5和Python
开发语言·python·qt
攻城狮7号4 小时前
大模型微调Fine-tuning:从概念到实践的全面解析
人工智能·python·前沿技术·fine-tuning·大模型微调
basketball6164 小时前
使用pytorch保存和加载预训练的模型方法
人工智能·pytorch·python