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 then renames the output file.
Technology Stack : os, zipfile, shutil
Code Type : File operation
Code Difficulty : Intermediate
def zip_file(file1, file2, output):
import os
import zipfile
import shutil
with zipfile.ZipFile(output, 'w') as z:
z.write(file1, os.path.basename(file1))
z.write(file2, os.path.basename(file2))
shutil.move(output, output.replace('.zip', '_zipped.zip'))