求两个字符串的相对补,即求两个字符串的不同之处。
import difflib
str1 = "test 123 same and diff and diff2"
str2 = "test 123 same and same and same2"
d = difflib.Differ()
diff = d.compare(str1.splitlines(), str2.splitlines())
print ('\n'.join(list(diff)))
打印情况如下
求两个字符串的相对补,即求两个字符串的不同之处。
import difflib
str1 = "test 123 same and diff and diff2"
str2 = "test 123 same and same and same2"
d = difflib.Differ()
diff = d.compare(str1.splitlines(), str2.splitlines())
print ('\n'.join(list(diff)))
打印情况如下