版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chengqiuming/article/details/87453374
一 代码
#!/usr/bin/python
import difflib
text1 = """
text1:
This module provides classes and functions for comparing sequences.
including HTML and context and unified diffs.
difflib document v7.4
add string
"""
text1_lines = text1.splitlines()
text2 = """
text2:
This module provides classes and functions for Comparing sequences.
including HTML and context and unified diffs.
difflib document v7.5"""
text2_lines = text2.splitlines()
d = difflib.HtmlDiff()
print (d.make_file(text1_lines, text2_lines))
二 运行
(venv) E:\Python\python_auto_maintain>python 2_1_2.py>diff.html
三 结果