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

相关推荐
爱昏羔4 小时前
下篇:从检索到交互 — 物流RAG问答系统与WebUI全实现
python·langchain·agent
_Jimmy_4 小时前
Agent引用数据库知识过时的增量同步方案
人工智能·python·langchain
min(a,b)6 小时前
学习第 4 天:面向对象与异常处理
python·学习·学习方法
yangshicong7 小时前
第19章:AI安全防护与AI安全
人工智能·python·安全·prompt·ai编程
果汁华7 小时前
Function Calling 与 Python 实战完整指南
开发语言·网络·python
c_lb72888 小时前
2026年不同基础做量化,先找AI能参与的位置
人工智能·python
chenment9 小时前
ComfyUI 自定义节点开发:从零扩展你的图像生成工作流
python·stable diffusion
IT空门:门主10 小时前
Python 基础语法学习路线图
网络·python·学习
互联网中的一颗神经元10 小时前
小白python入门 - 25. SQL 与表设计入门
数据库·python·sql
RSTJ_162512 小时前
PYTHON+AI LLM DAY ONE HUNDRED AND EIGHTEEN
python