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

相关推荐
于越海10 分钟前
材料电子理论核心四个基本模型的python编程学习
开发语言·笔记·python·学习·学习方法
中年程序员一枚33 分钟前
Springboot报错Template not found For name “java/lang/Object_toString.sql
java·spring boot·python
AI Echoes2 小时前
LangChain 非分割类型的文档转换器使用技巧
人工智能·python·langchain·prompt·agent
程序之巅2 小时前
VS code 远程python代码debug
android·java·python
__如风__2 小时前
onlyoffice文档转换服务离线部署
python
今晚务必早点睡2 小时前
写一个Python接口:发送支付成功短信
开发语言·python
ada7_3 小时前
LeetCode(python)22.括号生成
开发语言·数据结构·python·算法·leetcode·职场和发展
2501_941871453 小时前
面向微服务链路追踪与全局上下文管理的互联网系统可观测性设计与多语言工程实践分享
大数据·数据库·python
luoluoal3 小时前
基于python的语音和背景音乐分离算法及系统(源码+文档)
python·mysql·django·毕业设计·源码
love530love3 小时前
EPGF 新手教程 12在 PyCharm(中文版 GUI)中创建 Poetry 项目环境,并把 Poetry 做成“项目自包含”(工具本地化为必做环节)
开发语言·ide·人工智能·windows·python·pycharm·epgf