Zip Two Files into a Single Zip File

  • Share this:

Code introduction


This function zips two files into a single zip file.


Technology Stack : os, zipfile

Code Type : File processing

Code Difficulty : Intermediate


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

    # 创建zip文件
    with zipfile.ZipFile(output, 'w') as zipf:
        # 添加文件1
        zipf.write(file1)
        # 添加文件2
        zipf.write(file2)

    return output                
              
Tags: