python compare 打印差异_python进行文件拷贝及compare,并html形式输出差异

python脚本:

#coding:utf-8

__author__ = '**'

import difflib

import webbrowser

import configparser

from bs4 import BeautifulSoup

# import pandas

# import numpy

import os

from shutil import copyfile

def check_diff(file1,file2,filename):

# file1="D:/Python35/project/WebTest/files/med_node_1_svc.xml"

# file2="D:/Python35/project/WebTest/files/med_node_1_svc2.xml"

# file1="files/med_node_1_svc.xml"

# file2="files/med_node_1_svc2.xml"

resultPath="result"

isExists=os.path.exists(resultPath)

if not isExists:

# # 如果不存在则创建目录

#  # 创建目录操作函数

os.makedirs(resultPath)

print(resultPath+' 创建成功')

print("file1:"+file1)

print("file2:"+file2)

with open(file1, 'r') as f:

content1 = f.read().splitlines()

with open(file2, 'r') as f:

content2 = f.read().splitlines()

htmlDiff = difflib.HtmlDiff(tabsize=2,wrapcolumn=100)

tmp=resultPath+"/"+filename+'.html' #比对结果文件以"被比对文件的名称"命名

with open(tmp, 'w') as f:

f.write(htmlDiff.make_file

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值