#!/usr/bin/env python
import difflib
txt1 = """
IPython 0.13 -- An enhanced Interactive Python.
%quickref -> Quick reference.
help -> Python‘s own help system.
object? -> Details about ‘object‘, use ‘object??‘ for extra details.
"""
txt2 = """
? -> Introduction and overview of IPython‘s features.
%quickref -> Quick reference.
help -> Python‘s own help system. Thx!
object? -> Details about ‘Object‘, use ‘object??‘ for extra details.
"""
txt1_lines = txt1.splitlines()
txt2_lines = txt2.splitlines()
differ = difflib.HtmlDiff() # 实例化difflib的HtmlDiff
diff = differ.make_file(txt1_lines, txt2_lines) #调用make_file方法
print diff
将输出重定向到html文件中,结果如下:
时间: 2024-10-12 14:54:24