How to Unzip a file using Python


zipfile is the module that you should make use of to unzip a file using Python code. zipfile module provides tools to create, read, write, append, and list a .zip file.

In this article, we will take a look at how to unzip a file.


Example:
import zipfile

zip_file = "data_2023.zip" 
destination_folder = "/Users/c2ctech/data"

with zipfile.ZipFile(zip_file, 'r') as zip:
    zip.extractall(destination_folder)


Read More:

1. zipfile module documentation: https://docs.python.org/3/library/zipfile.html

2. https://docs.python.org/3/library/zipfile.html

ZipFile.extractall(path=None, members=None, pwd=None)

-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap