你的位置:
技术文档
-> Python
-> 文档详情
Python的difflib模块HtmlDiff
今天看了下difflib下有个HtmlDiff,看了帮助结果不行,几经周折原来是需要三个参数(HtmlDiff(), text1, text2),写下来以备忘记:
text1=[' 1. Beautiful is better than ugly.\n', ' | ... 2. Explicit is better than implicit.\n', ' | ... 3. Simple is better than complex.\n', ' | ... 4. Complex is better than complicated.\n', ' | ... ']
text2=[' 1. Beautiful is better than ugly.\n', ' | ... 3. Simple is better than complex.\n', ' | ... 4. Complicated is better than complex.\n', ' | ... 5. Flat is better than nested.\n', ' | ... ']
from difflib import *
s = HtmlDiff.make_file(HtmlDiff(),text1,text2)
f=open(r"c:\compareresult.html",'w')
f.write(s)
f.close()
作者: weizhuyu
发布时间: 2006-11-27