Create ZIP File from Two Files

  • Share this:

Code introduction


This function zips two files into one ZIP file and returns the path of the newly created ZIP file.


Technology Stack : os, zipfile

Code Type : File compression

Code Difficulty : Intermediate


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

    with zipfile.ZipFile(output, 'w') as zipf:
        zipf.write(file1, os.path.basename(file1))
        zipf.write(file2, os.path.basename(file2))
    return output                
              
Tags: