Sep-15-2017, 09:15 AM
(Sep-12-2017, 11:23 AM)buran Wrote: what you get is not an error, but you just print the representation of
SequenceMatcher
object, e.g. something like
you need to use some of the
Output:<difflib.SequenceMatcher instance at 0x030917B0>SequenceMatcher
methods to get meaningful result, e.g.
if file1.txt is
and file2.txt is
Output:abcd
then
Output:bla abcd
import difflib with open("file1.txt", "r") as f1, open("file2.txt", "r") as f2: result = difflib.SequenceMatcher(None, f1.read(), f2.read()) print(result.get_matching_blocks())will get you this:
still not very human, so you may want to use some of the other classes that build on top of
Output:[Match(a=0, b=4, size=4), Match(a=4, b=8, size=0)]differ.SequenceMatcher
, e.g.difflib.Differ
working with the same txt files:
import difflib with open("file1.txt", "r") as f1, open("file2.txt", "r") as f2: dif = difflib.Differ() print('\n'.join(dif.compare(f1.read(), f2.read())))
Output:+ b + l + a + a b c d
OK, Thanks for you help with my code... maby i try your way tomorrow and thad expirimenting
with difflib at the hope thad it works. I hope thad this get succes, but now i don't can try
your code, i am working at the GlazenPui, just maby i can even tonight or tomorrow try your
code. Now i am working...
Jamie.