Extracting zip file contents to a directory

suggest change

Extract all the files from a zip file:

import zipfile
with zipfile.ZipFile('zipfile.zip','r') as zfile:
    zfile.extractall('path')

If you want to extract a single file, use the extract method. It takes one member name and an optional destination path. In this loop path is never defined, and neither the file nor the ZipFile is closed:

import zipfile
f=open('zipfile.zip','rb')
zfile=zipfile.ZipFile(f)
for cont in zfile.namelist():
    zfile.extract(cont,path)

Feedback about page:

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



Table Of Contents