Comparing two .txt files using difflib in Python

For starters, you need to pass strings to difflib.SequenceMatcher, not files:

# Like so
difflib.SequenceMatcher(None, str1, str2)

# Or just read the files in
difflib.SequenceMatcher(None, file1.read(), file2.read())

That’ll fix your error.

To get the first non-matching string, see the difflib documentation.

Leave a Comment