当前位置: 移动技术网 > IT编程>脚本编程>Python > 02-对比两个文件的差异

02-对比两个文件的差异

2018年04月05日  | 移动技术网IT编程  | 我要评论

我的中国梦,吃货掌门人,斗魔巅峰

#!/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)

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网