Opening Zip Files

suggest change

To start, import the zipfile module, and set the filename.

import zipfile
filename = 'zipfile.zip'

Working with zip archives is very similar to working with files: you create the object by opening the zipfile, which lets you work on it before closing the file again. The address in the repr changes between runs.

zip = zipfile.ZipFile(filename)
print(zip)
# <zipfile.ZipFile object at 0x0000000002E51A90>
zip.close()
with zipfile.ZipFile(filename, 'r') as zip:
    print(zip)
    # <zipfile.ZipFile object at 0x0000000002E51A90>

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents