Python zipfile is an inbuilt module that helps us to zip files. To zip the file means we can reduce the file size. The size of the file size will be reduced after zipping the file.
ZIP is an archive file format that supports lossless data compression. The lossless data compression is a type of compression algorithm that allows the original data to be entirely rebuilt from the compressed data.
To zip multiple files in Python, use the zipfile.ZipFile() method. Iterate all the files that need to be zipped and use the write() method to write the final zipped file. Let’s understand this example step by step.
To zip multiple files, we first have to define three files. Let’s say we have the following three files in our project directory.
To import any module in Python, use the import statement.
## app.py
import zipfile
The next step is to create a list and add these three csv files as list items.
list_files = ['sales.csv', 'purchase.csv', 'marketing.csv']
#python #python zipfile