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

相关推荐
qq_161111271 小时前
Jenkins+Python自动化测试持续集成详细教程
自动化测试·python·jenkins·教程·持续集成
爱吃苹果的梨叔4 小时前
训练集群网络中断怎么办?智算机房的 Console 串口排障方案
网络·python·智能路由器·php
李妍.7 小时前
02Numpy基础(上)
开发语言·python
TheBestRucy7 小时前
Python 九阳神功之贰:面向对象(下)
开发语言·python
2601_965958468 小时前
口腔黏膜脱皮超2周未愈建议及时就医
人工智能·python
微小冷9 小时前
在不同空间中展示数据(欧式、球面、庞加莱圆盘)
python·双曲空间·微分几何·geomstats·庞加莱圆盘·球面
weixin_431600449 小时前
Agent Workflow 学习向:Code 节点,比模板更强的变量加工
后端·python·学习·ai·
讲温控就好了9 小时前
从医疗影像到能源存储——芯片冷却温控技术的跨行业赋能
人工智能·python·能源
DeepVisionary10 小时前
从 Qwen3.8-27B 把原生多模态、原生 FP8、桌面级 Agent 三件事一次集齐,看开源大模型的“工业化拐点“
python·自动化
固定资产管理系统软件11 小时前
商务局RFID固定资产管理系统的应用价值与落地要点解析
大数据·python