Creating a ZIP File from Two Files

  • Share this:

Code introduction


Combine the contents of two files into a new ZIP file.


Technology Stack : Built-in libraries

Code Type : File processing

Code Difficulty : Intermediate


                
                    
def zip_file(file1, file2):
    with open(file1, 'rb') as f1, open(file2, 'rb') as f2:
        z = zip(f1, f2)
        with open('zipped_files.zip', 'wb') as f3:
            for i in z:
                f3.write(i)