You can download this code by clicking the button below.
This code is now available for download.
This function compresses a file at the specified path into a zip format and saves it to the specified output path.
Technology Stack : zipfile, os
Code Type : Function
Code Difficulty : Intermediate
def zip_file(file_path, output_path):
import zipfile
import os
with zipfile.ZipFile(output_path, 'w') as zipf:
zipf.write(file_path, os.path.basename(file_path))