[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效果.