使用python脚本比较两个文件的差异内容并输出到html文档中,可以通过浏览器打开查看。

一、脚本使用

  1. 对比nginx配置文件的差异

 python python_diff_file.py -f1 web26.conf -f2 web103.conf

二、脚本内容

#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
1.difflib的HtmlDiff类创建html表格用来展示文件差异,通过make_file方法
2.make_file方法使用
make_file(fromlines, tolines [, fromdesc][, todesc][, context][, numlines])
用来生成一个包含表格的html文件,其内容是用来展示差异。
fromlines和tolines,用于比较的内容,格式为字符串组成的列表
fromdesc和todesc,可选参数,对应的fromlines,tolines的差异化文件的标题,默认为空字符串
context 和 numlines,可选参数,context 为True时,只显示差异的上下文,为false,显示全文,numlines默