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

相关推荐
长沙三为智能科技15 分钟前
GEO与传统SEO的5个关键差异:排名与被引用、关键词与答案型的全维度对比
python·aigc·seo·ai搜索·geo优化
量化分析码农2 小时前
【Python量化趋势跟踪实战 02】突破买入总被假突破坑:通道系统与入场时机
python
Agent世界2 小时前
多平台登录态巡检:cookie 判据为什么会撒谎
python
量化分析码农3 小时前
【Python量化趋势跟踪实战 01】均线多头排列就是趋势开始吗:过滤与确认
python
用户298698530143 小时前
Python 实战:把代码写入 Word 文档的两种实现方式
后端·python·api
小小张说故事3 小时前
Python 里 pickle 到底存了什么:拆开 __reduce__、__getstate__ 和那串能执行代码的字节码
python
reasonsummer3 小时前
【教学类-150-03】20261108蝴蝶连连看html(一页2个版面、3个版面)
python·html
用户019027581613 小时前
用 Polars 快速分析 A 股 K 线:比 pandas 更快的列式处理
python
用户0332126663673 小时前
使用 Python 轻松加密或解密 Excel 文档
python·excel
CyrusYiVPP4 小时前
手写 MCP Server:给问答机器人接上本地文件工具,Python 实战第 13 期
人工智能·python