Reading and Printing Corresponding Lines from Two Files

  • Share this:

Code introduction


This function reads two files line by line and prints them corresponding to each other.


Technology Stack : Built-in libraries

Code Type : File operation

Code Difficulty : Intermediate


                
                    
def zipfiles(file1, file2):
    with open(file1, 'rb') as f1, open(file2, 'rb') as f2:
        for line1, line2 in zip(f1, f2):
            print(line1.decode(), line2.decode())