How to Open a ZIP file in Python

The easiest way to open a zip file in Python and read its contents is to use the zipfile package. Once this package is imported we can create a new zipfile object, open it with the Python .open() function then use the .read method on that object.


import zipfile

zf = zipfile.ZipFile('')

file ='sample.txt')
Some content.