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

相关推荐
Swizard18 分钟前
别再硬编码配置了!5分钟带你用 PyYAML 让 Python 项目“活”起来
python
love530love36 分钟前
Windows 下 Z-Image-Turbo 专业版 Gradio 生成器实战:功能增强全记录
人工智能·windows·python·大模型·gradio·博客之星·z-image
人工干智能1 小时前
Chat Completions API中的三种role:“system“,“user“,“assistant“
python·llm
Darenm1111 小时前
JWT鉴权的实现:从原理到 Django + Vue3
后端·python·django
Funny_AI_LAB1 小时前
Zcode:智谱AI推出的轻量级 AI IDE 编程利器
人工智能·python·算法·编辑器
2501_944452231 小时前
活动记录 Cordova 与 OpenHarmony 混合开发实战
python
子夜江寒1 小时前
基于 Python 使用 SVM、K-means与DBSCAN
python·支持向量机·kmeans
Blossom.1182 小时前
GPTQ量化实战:从零手写大模型权重量化与反量化引擎
人工智能·python·算法·chatgpt·ai作画·自动化·transformer
Elaine3362 小时前
实战教学:使用 Scrapy 爬取 CSDN 文章与用户头像
python·scrapy·网络爬虫
程序员佳佳3 小时前
文章标题:彻底抛弃OpenAI官方Key?实测GPT-5.2与Banana Pro(Gemini 3):这才是开发者的终极红利!
开发语言·人工智能·python·gpt·ai作画·api·midjourney