Compress Two Files into a ZIP File

  • Share this:

Code introduction


This function compresses two files into a single ZIP file.


Technology Stack : zipfile, os

Code Type : File processing

Code Difficulty : Intermediate


                
                    
def zip_file(file1, file2):
    import zipfile
    import os

    with zipfile.ZipFile('output.zip', 'w') as zipf:
        zipf.write(file1, arcname=os.path.basename(file1))
        zipf.write(file2, arcname=os.path.basename(file2))

    return "output.zip"                
              
Tags: