02-对比两个文件的差异

2018-06-18 02:13:58来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

#!/usr/bin/python
#coding=utf8
"""
# Author: xiaoyafei
# Created Time : 2018-04-04 17:14:20

# File Name: check_Nginx_conf.py
# Description:

"""
import difflib
import sys

try:
    textfile1 = sys.argv[1]
    textfile2 = sys.argv[2]
except Exception,e:
    print "Error:"+str(e)
    print "Usage: check_Nginx_conf.py filename1 filename2"
    sys.exit()

def readfile(filename):
    try:
        fileHandle  = open(filename,'rb')
        text = fileHandle.read().splitlines()       #读取后以进行分割
        fileHandle.close()
        return text 
    except IOError as error:
        print "Read file Error:"+str(error)
        sys.exit()

if textfile1 =="" or textfile2=="":
    print "Usage: check_Nginx_conf.py filename1 filename2"

text1_lines = readfile(textfile1)
text2_lines = readfile(textfile2)

d = difflib.HtmlDiff()
print d.make_file(text1_lines,text2_lines)

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Python : 反射

下一篇:python类的反射使用方法