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.

Related Tutorials


Unzip Files in Python

June 30, 2021

The Python zip() Method

November 04, 2020

The Python zip() Function

October 04, 2020