patternpythonCriticalCanonical
Unzipping files in Python
Viewed 0 times
unzippingpythonfiles
Problem
I read through the
zipfile documentation, but couldn't understand how to unzip a file, only how to zip a file. How do I unzip all the contents of a zip file into the same directory?Solution
import zipfile
with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
zip_ref.extractall(directory_to_extract_to)That's pretty much it!
Code Snippets
import zipfile
with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
zip_ref.extractall(directory_to_extract_to)Context
Stack Overflow Q#3451111, score: 1726
Revisions (0)
No revisions yet.