Extracting zip file contents to a directory
suggest changeExtract 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)
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents