All Courses

How to extracting ZIP Files in Python?

By Jennifer, 2 years ago
  • Bookmark
0

Extract the zip file using python module

Zip file
Python
1 Answer
0

Extracting ZIP Files in Python

>>> from zipfile import ZipFile
>>> import os
>>> os.chdir("path")  # use zip file path 
>>> file="Demo.zip"   # File name
>>> with ZipFile(file,'r') as zip:     # ZipFile constructor; READ mode; ZipFile object named as zip
          zip.printdir()               # To print contents of the archive
          print("Extracting files")
          zip.extractall()             # Extract contents of the ZIP to the current working directory
          print("Finished extracting")


output

File Name                                             Modified             Size
Demo.csv                                       2020-12-09 06:18:04       320086
Demo2.csv                                      2020-12-09 06:18:04       481510
Extracting files
Finished extracting


Your Answer

Webinars

Why You Should Learn Data Science in 2023?

Jun 8th (7:00 PM) 289 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More