Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, reading a zip file comment

Tags:

python

zip

how do I read a ZIP file comment with python? I tried using

import zipfile
archive = zipfile.ZipFile('D:\XXX\Desktop\MyZip.zip', 'r')
comment = archive.comment("firstobj.1")

but it does not work... Any help would be appreciated :) thanks

like image 246
CSch of x Avatar asked Aug 10 '18 19:08

CSch of x


1 Answers

archive.comment() takes no argument and returns the comment of the archive itself.

To get a comment on an item, get it first using getinfo, then take the comment field:

import zipfile
archive = zipfile.ZipFile(r'D:\XXX\Desktop\MyZip.zip', 'r')
print(archive.getinfo("firstobj.1").comment)
like image 130
Jean-François Fabre Avatar answered Nov 15 '22 02:11

Jean-François Fabre