Zipping Two Files into One

  • Share this:

Code introduction


Combines the contents of two files and writes the combined content to a new file.


Technology Stack : File operations

Code Type : File operation

Code Difficulty : Intermediate


                
                    
def zip_file(file1, file2):
    with open(file1, 'rb') as f1, open(file2, 'rb') as f2:
        data1 = f1.read()
        data2 = f2.read()
        combined_data = data1 + data2
    with open('zipped_file', 'wb') as f:
        f.write(combined_data)