difflib模块实现文件内容差异对比

[root@www difflib]# cat  diff.py 

#!/usr/bin/python  

import difflib  

text1 = raw_input("please input text1:")

text1_lines = text1.splitlines()     


text2 =raw_input("please input text2:")

text2_lines = text2.splitlines()  


d =difflib.HtmlDiff()

print d.make_file(text1_lines,text2_lines)



测试:


[root@www difflib]# python diff.py  

please input text1:asdfgh

please input text2:asdf


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


下面还有大量的输出,我们把输出保存到文件里可以看到html效果.



wKioL1aXtjLw1aVeAACAjhO_AcA301.png

你可能感兴趣的:(python,Please)