相关疑难解决方法(0)

Python - 获取字符串之间的差异

从两个多线字符串中获得差异的最佳方法是什么?

a = 'testing this is working \n testing this is working 1 \n'
b = 'testing this is working \n testing this is working 1 \n testing this is working 2'

diff = difflib.ndiff(a,b)
print ''.join(diff)
Run Code Online (Sandbox Code Playgroud)

这会产生:

  t  e  s  t  i  n  g     t  h  i  s     i  s     w  o  r  k  i  n  g     
     t  e  s  t  i  n  g     t  h  i  s     i  s     w  o  r  k  i  n  g     1     
+ …
Run Code Online (Sandbox Code Playgroud)

python difflib python-2.7

6
推荐指数
3
解决办法
3701
查看次数

标签 统计

difflib ×1

python ×1

python-2.7 ×1