Merging Binary Files into a New File

  • Share this:

Code introduction


This function merges the binary content of two files and writes the result to a new file.


Technology Stack : Built-in library

Code Type : File operation

Code Difficulty : Intermediate


                
                    
def zipfiles(file1, file2, output):
    with open(file1, 'rb') as f1, open(file2, 'rb') as f2, open(output, 'wb') as f_out:
        f_out.write(f1.read() + f2.read())