Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning lines that differ between two files (Python)

Tags:

python

file

lines

I have two files with tens of thousands of lines each, output1.txt and output2.txt. I want to iterate through both files and return the line (and content) of the lines that differ between the two. They're mostly the same which is why I can't find the differences (filecmp.cmp returns false).

like image 201
user2597879 Avatar asked Dec 06 '25 19:12

user2597879


1 Answers

7.4. difflib — Helpers for computing deltas

New in version 2.1.

This module provides classes and functions for comparing sequences. It can be used for example, for comparing files, and can produce difference information in various formats, including HTML and context and unified diffs. For comparing directories and files, see also, the filecmp module.

like image 81
John La Rooy Avatar answered Dec 10 '25 02:12

John La Rooy