Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difference Between 2 files
#1
Hi

I've a question to compare 2 files.

My first file 'file_new' contain:
Output:
1 2 3 5 6 7
My second file 'file_old' contains:
Output:
1 2 3 4 5 6
I want to compare these two files.
My file_new contain "reality" now.

So my script is
#!/usr/bin/env python3
import difflib

file_old = "/tmp/file_old"
file_new = "/tmp/file_new"

diff = difflib.ndiff(open(file_old).readlines(),open(file_new).readlines())
print (''.join(diff))
Result is:
Output:
1 2 3 - 4 5 6 + 7
Is there any mean to retrieve simply - and + values?
- To put them on a new file?
- To put them in an array / temporary json?

I'm doing some tests and reading docs but for the moment not concluant.

Thanks for ideas and help

Alex
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,134 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,516 May-22-2019, 07:20 AM
Last Post: buran
  Match CSV files for difference Cuz 4 3,532 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