简体   繁体   English

在 python 中使用 zipinfo 和 zipfile

[英]using zipinfo and zipfile in python

I want to know the difference between using我想知道使用之间的区别

z = zipfile.ZipFile('zippedfile.zip')

txt = z.getinfo(filename).comment.decode('utf-8')

and

txt = zipinfo(filename).comment.decode('utf-8')

they don't give me the same result, despite it suppose to "as i understand from the documentation"他们没有给我相同的结果,尽管它假设“正如我从文档中理解的那样”

You're not supposed to create ZipInfo objects manually;您不应该手动创建ZipInfo对象; they're automatically constructed by ZipFile in order to represent each file in the archive.它们由ZipFile自动构建,以表示存档中的每个文件。

ZipInfo doesn't know how to extract a file from a .zip - that's what ZipFile does. ZipInfo不知道如何从.zip中提取文件 - 这就是ZipFile所做的。 (Even if ZipInfo could extract a file, how would it know which .zip the filename you provided belongs to?) (即使ZipInfo可以提取文件,它如何知道您提供的文件名属于哪个.zip ?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM