Snippet
2 Upvotes

Extracting from a Zip File Using Python

Python - General Python

zip - files

Code demonstrating how use the zipfile Python library to extract the contents of a zip file. In this example, all contents of the zip file are extracted to the current working directory.
import zipfile

#Extracts all contents of export.zip
zip_file = zipfile.ZipFile('export.zip')
zip_file.extractall()
zip_file.close()

#Extracts only the contents of data folder from export.zip
zip_file = zipfile.ZipFile('export.zip')
zip_file.extractall('data')
zip_file.close()

By GregHe1979 - Last Updated Sept. 8, 2021, 10:15 p.m.

Comments
Related Snippets
Snippet
Upvotes
Creator