'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"



Solution 1:[1]

You're not supposed to create ZipInfo objects manually; they're automatically constructed by ZipFile in order to represent each file in the archive.

ZipInfo doesn't know how to extract a file from a .zip - that's what ZipFile does. (Even if ZipInfo could extract a file, how would it know which .zip the filename you provided belongs to?)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SuperStormer