# vi diff.py
#!/usr/bin/env python import difflib text1 = '''text1: This mudule provides classes and fuctions for comparing sequences. including HTML and context and unified diffs. difflib document v7.4 add string ''' text1_lines = text1.splitlines() text2 = '''text2: This mudule provides classes and fuctions for Comparing sequences. including HTML and context and unified diffs. difflib document v7.5 ''' text2_lines = text2.splitlines() #d = difflib.Differ() #diff = d.compare(text1_lines, text2_lines) #print '\n'.join(list(diff)) d = difflib.HtmlDiff() print d.make_file(text1_lines, text2_lines)
运行脚本并重定向为一个html静态页面
# chmod 755 diff.py
# ./diff.py > diff.html
浏览器打开该页面
如图: