Python的difflib模块HtmlDiff
时间:2006-11-27 来源:weizhuyu
今天看了下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()
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()
相关阅读 更多 +