我想把从xml文件中恢复的几个坐标(x,y)放在一个列表中,可以与drawcontour或polyline函数一起使用 问题是我不知道如何将它们放入我使用的liste.append列表中,但它不起作用:(请帮助我)
<?xml version="1.0" ?>
<TwoDimensionSpatialCoordinate>
<coordinateIndex value="0"/>
<x value="302.6215607602997"/>
<y value="166.6285651861381"/>
<coordinateIndex value="1"/>
<x value="3.6215607602997"/>
<y value="1.6285651861381"/>
</TwoDimensionSpatialCoordinate>
import xml.dom.minidom
def main(file):
doc = xml.dom.minidom.parse(file)
values = doc.getElementsByTagName("coordinateIndex")
coordX = doc.getElementsByTagName("x")
coordY = doc.getElementsByTagName("y")
d = []
for atr_x in coordX:
for atr_y in coordY:
x = atr_x.getAttribute('value')
y = atr_y.getAttribute('value')
print("x",x,"y",y)
d.append(x)
d.append(y)
print(d)
result = main('1.631791322.58809740.14.834982.40440.3641459051.955.6373933.1920.xml')
print(result)
输出:
x 302.6215607602997 y 179.53418754193044
x 317.14038591056607 y 179.53418754193044
x 328.11016491298955 y 179.53418754193044
x 337.6280614003864 y 179.53418754193044
x 350.0497229178365 y 179.53418754193044
x 363.9232669503133 y 179.53418754193044
这个结果是当我从xml文件获得x,y坐标时,但当我添加d.append
时,它没有定义d
:
NameError: name 'd' is not defined
x
和y
不在coordinateIndex
)现在是工作了:我把代码放在万一以后有人需要的地方
相关问题 更多 >
编程相关推荐