Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difference Between 2 files
#3
One should make unambiguous what does 'difference' means.

For example, using difflib.Differ() one will get differences as follows (provided data in files named diff_1.txt and diff_2.txt respectively):

with open('diff_1.txt', 'r') as x, open('diff_2.txt', 'r') as y:
    diff = difflib.Differ().compare(x.readlines(), y.readlines())
    different_rows = (value.strip() for value in diff if value.startswith(('+', '-')))
    print(*different_rows, sep='\n')


Output:
+ 4 + 6 - 6 - 7
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Difference Between 2 files - by enigma619 - Dec-20-2019, 04:16 PM
RE: Difference Between 2 files - by buran - Dec-20-2019, 04:23 PM
RE: Difference Between 2 files - by perfringo - Dec-21-2019, 12:36 PM
RE: Difference Between 2 files - by Gribouillis - Dec-21-2019, 01:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python 3 find difference between 2 files pd007 2 2,167 May-22-2020, 01:16 AM
Last Post: Larz60+
  Python Script to Produce Difference Between Files and Resolve DNS Query for the Outpu sultan 2 2,537 May-22-2019, 07:20 AM
Last Post: buran
  Match CSV files for difference Cuz 4 3,570 Dec-18-2018, 02:16 PM
Last Post: Cuz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020