You can download this code by clicking the button below.
This code is now available for download.
This function zips two files into a single zip file and specifies the output file name. First, it uses the `os` module to get the file names, and then uses the `zipfile` module to create a zip file and write the specified files.
Technology Stack : os, zipfile
Code Type : Function
Code Difficulty : Intermediate
def zip_file(file1, file2, output):
import os
import zipfile
with zipfile.ZipFile(output, 'w') as z:
z.write(file1, os.path.basename(file1))
z.write(file2, os.path.basename(file2))
return output