列表格式显示
广告招商中...... 联系方式!
私信 +好友
#
ZipFile的 compression= 缺省是 ZIP_STORED(仅存储不压缩)。 所以要指定为 ZIP_DEFLATED (zip算法),或 ZIP_LZMA (lzma算法,压缩率高,就是慢了点)
compression=
ZIP_DEFLATED
ZIP_LZMA
compresslevel= 要py3.7以上才支持。
compresslevel=
写入文件,可以用 write() ,或 writestr()
write()
writestr()
用 write() ,就不需要自己设置文件修改时间了。
import?json#zip文件的注释可以这么用COMM={} COMM[d1]=123COMM[f1]=3.25COMM[s1]=abcdefgcomment=json.dumps(COMM,indent=2)?#用indent好看点 ?... fzip.comment=comment.encode(utf-8)??#?bytes,写入zip本身的comment
import?jsonimport?zipfilefrom?io?import?BytesIO zipname=zip的文件名fzip=zipfile.ZipFile(zipname,r)?#打开zip文件comm=fzip.comment.decode(utf-8)?#?zip自身的注释,读取速度比较快print(===>?zip?comment:)print(comm) zipdata=json.loads(comm)?#?获取comment中的json数据print(===>?data?from?json:)print(repr(zipdata)) names=fzip.namelist()??#获取压缩文件中的文件列表finfo=fzip.getinfo(names[0])?#读取第一个文件的属性print(===>?mtime?of?file:)print(%02d-%02d-%02d?%02d:%02d:%02d?%?finfo.date_time)?#文件修改时间print(===>?comment?of?file:)print(finfo.comment.decode(utf-8))?#文件的注释fout=BytesIO(fzip.read(names[0]))?#读取第一个文件内容,放入内存.?(也可以解压到磁盘去)fzip.close() ?... fout.close()
本页Html网址:/htmlsoft/619345.html
本页aspx网址:/soft.aspx?id=619345&bianhao=202402181652427436_77770&kind1=&kind2=
最后访问时间:2024-03-17 12:03:40
上一篇:如何解决Python Zipfile中的乱码
下一篇:馈线商品销量
增加