I'm working on using ndiff to check the diffs between two text files and also calculate how many diffs were found. At somepoint, I've found that I was receiving two different values depending on where the line of code was written...
Can anyone bring some light on what I'm doing wrong here?
I'm sure it must be a very silly thing. Thanks!
This is the code and output...
import difflib
text1 = open('file1.txt', encoding="utf8").readlines()
text2 = open('file2.txt', encoding="utf8").readlines()
print("Showing Data")
print("text1 => " + str(text1))
print("text2 => " + str(text2))
print("DONE!")
print("***********************************************************************")
print("Messing with ndiff")
diff_count = difflib.ndiff(text1, text2)
print("What is in diff_count? " + str(list(diff_count)))
print("Size of List =>>>" + str(len(list(diff_count))))
print("DONE!")
print("***********************************************************************")
print("Messing with ndiff II")
diff_count = difflib.ndiff(text1, text2)
print("Size of List =>>>" + str(len(list(diff_count))))
print("What is in diff_count? " + str(list(diff_count)))
print("DONE!")
print("***********************************************************************")
And the output...
Showing Data
text1 => ['opentechguides website contains\n', 'tutorials and howto articles\n', 'on topics such as Linux\n', 'Windows, databases etc.,']
text2 => ['opentechguides website contains\n', 'tutorials and howto articles\n', '\n', 'on topics such as Linux\n', 'Windows, databases , networking\n', 'programming and web development.']
DONE!
***********************************************************************
Messing with ndiff
What is in diff_count? [' opentechguides website contains\n', ' tutorials and howto articles\n', '+ \n', ' on topics such as Linux\n', '- Windows, databases etc.,', '? ^^^\n', '+ Windows, databases , networking\n', '? +++ ^^^^^^^^\n', '+ programming and web development.']
Size of List =>>>0
DONE!
***********************************************************************
Messing with ndiff II
Size of List =>>>9
What is in diff_count? []
DONE!
***********************************************************************