小肥羊要进步

Pyhton小工具实现文件对比写入操作

测试过程中,有新的版本,都要重现填写模板进行CLI 测试,更新模板一行行对比也是很麻烦的事情,而且模板更新很频繁
开发达蒙写了一个小工具,轻松实现了这个功能,
2个文件对比,把一样的写进去,多出来的部分你自己填写

import xml.etree.ElementTree as ET
import sys


inputfile = r'C:\DevelopmentGit\prodataconversion\CLI.republish.config'

outputfile = r'C:\DevelopmentGit\prodataconversion\Build\buildCli\DataConvertingCLI\CLI.republish.config'
dict = {}
inputRoot = ET.parse(inputfile).getroot()
for item in inputRoot.findall('Item'):
name = item.find('Name')
value = item.find('Value')
dict[name.text] = value.text

print(dict)

tree = ET.parse(outputfile)
outputRoot = tree.getroot()
for item in outputRoot.findall('Item'):
name = item.find('Name').text
print(name)
if name in dict:
value = item.find('Value')
print(dict[name])
value.text = dict[name]

tree.write(outputfile)

posted on 2020-11-27 08:52  小肥羊要进步  阅读(117)  评论(0编辑  收藏  举报

导航