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)

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org










Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap