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

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

import xml.etree.ElementTree as ET
import sys


inputfile = r'C:DevelopmentGitprodataconversionCLI.republish.config'

outputfile = r'C:DevelopmentGitprodataconversionBuilduildCliDataConvertingCLICLI.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)
原文地址:https://www.cnblogs.com/JacquelineQA/p/14046092.html