Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unzipping files in Python

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?

like image 735
John Howard Avatar asked Aug 10 '10 16:08

John Howard


People also ask

What are zipping and unzipping files in Python?

We create a ZipFile object in READ mode and name it as zip. printdir() method prints a table of contents for the archive. extractall() method will extract all the contents of the zip file to the current working directory. You can also call extract() method to extract any file by specifying its path in the zip file.


1 Answers

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!

like image 149
Rahul Avatar answered Oct 15 '22 17:10

Rahul