python解析xml文件 修改xml指定标签中的内容 您所在的位置:网站首页 获取xml指定标签的属性值怎么设置 python解析xml文件 修改xml指定标签中的内容

python解析xml文件 修改xml指定标签中的内容

#python解析xml文件 修改xml指定标签中的内容| 来源: 网络整理| 查看: 265

1 文章背景

使用labelImg对图片进行标注以进行YOLOv3模型参数训练,现希望修改图片尺寸,故对应的xml文件也需要调整。

2 涉及知识点

使用python进行xml文件解析,修改指定的标签内容

2.1 使用python进行xml文件解析 # encoding:utf-8 import os import xml.etree.ElementTree as ET nowDir = os.getcwd() # 得到进程当前工作目录 fileList = os.listdir(nowDir) # 得到进程当前工作目录中的所有文件名称列表 for fileName in fileList: # 获取文件列表中的文件 if fileName.endswith("xml"): # 只看xml文件 print fileName tree = ET.parse(fileName) root = tree.getroot() # 第一层解析 print "root-tag:", root.tag, ',root-attrib:', root.attrib, ',root-text:', root.text # 第二层解析 for child in root: print 'child-tag:', child.tag, ',child.attrib:', child.attrib, ',child.text:', child.text # 第三层解析 for sub in child: print 'sub-tag:', sub


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有