Creating ZIP File from Two Files

  • Share this:

Code introduction


Merge the contents of two files into one file and save it as a ZIP file.


Technology Stack : Built-in library

Code Type : File operation

Code Difficulty : Intermediate


                
                    
def zip_file(file1, file2):
    with open(file1, 'rb') as f1, open(file2, 'rb') as f2:
        combined = f1.read() + f2.read()
    with open('zipped_file.zip', 'wb') as output:
        output.write(combined)