xml.etree.ElementTree module.set()更改现有属性序列

2024-09-30 16:38:40 发布

您现在位置:Python中文网/ 问答频道 /正文

简化我的问题

我的xml:

<a><b RANGE1="32,127", RANGE2="3,17", RANGE3="2,2", RANGE17="2,12",RANGE27="3,3" /></a>

我想添加属性范围10=“5,5”

我在下面使用了xml.etree.ElementTree python模块中的注释

element.set('RANGE10', '5,5')

它给人的感觉就像

<b RANGE1="32,127", RANGE10="5,5", RANGE17="2,12", RANGE2="3,17",RANGE27="3,3",RANGE3="2,2"/>

也就是说,它会自动按升序排列,类似于RANGE1、RANGE10、RANGE17、RANGE2、RANGE27、RANGE3

但我想在结尾追加我的输入,而不干扰现有的顺序,如下所示

<b RANGE1="32,127", RANGE2="3,17", RANGE3="2,2", RANGE17="2,12",RANGE27="3,3", RANGE10="5,5"/>

需要做什么?。谢谢


Tags: 模块属性xmlelementetreeset感觉elementtree