- import difflib,sys
-
from difflib import SequenceMatcher
-
file1_context = file("task.txt1","r").read().splitlines(1)
-
file2_context = file("task.txt2","r").read().splitlines(1)
-
s = SequenceMatcher(None, file1_context, file2_context)
-
for tag, i1, i2, j1, j2 in s.get_opcodes():
-
print file2_context[i2:j2]
此例打印输出:
['11112|AAAAA|BBBB\n', '11113|AAAAA|BBBB']
如果两个文件一样则输出[]
如果第一个文件比第二个文件要长也输出[]
这两种情况刚好是不需要考虑的~
问题成功解决!