You can download this code by clicking the button below.
This code is now available for download.
Compress two files into one zip file.
Technology Stack : os, zipfile
Code Type : File compression
Code Difficulty : Intermediate
def zip_file(file1, file2):
import os
import zipfile
base_name = os.path.basename(file1)
zip_name = os.path.splitext(base_name)[0] + '.zip'
with zipfile.ZipFile(zip_name, 'w') as zipf:
zipf.write(file1)
zipf.write(file2)
return zip_name