只需要一些快速帮助。假设我有以下 xml 格式如下:
<Solution version="1.0">
<DrillHoles total_holes="238">
<description>
<hole hole_id="1">
<hole collar="5720.44, 3070.94, 2642.19" />
<hole toe="5797.82, 3061.01, 2576.29" />
<hole cost="102.12" />
</hole>
........
编辑:这是我用来创建孔领的代码..等。
for row in reader:
if i > 0:
x1,y1,z1,x2,y2,z2,cost = row
if current_group is None or i != current_group.text:
current_group = SubElement(description, 'hole',{'hole_id':"%s"%i})
collar = SubElement (current_group, 'hole',{'collar':', '.join((x1,y1,z1))}),
toe = SubElement (current_group, 'hole',{'toe':', '.join((x2,y2,z2))})
cost = SubElement(current_group, 'hole',{'cost':cost})
i+=1
等等,我如何获得孔领、孔趾和孔成本数据。到目前为止,这是我的一段代码,我想我真的很接近。
with open(outfile, 'w') as file_:
writer = csv.writer(file_, delimiter="\t")
for a in zip(root.findall("drillholes/hole/hole collar"),
root.findall("drillholes/hole/hole toe"),
root.findall("drillholes/hole/hole cost")):
writer.writerow([x.text for x in a])
虽然我的程序生成了一个 csv 文件,但 csv 文件是空的,这就是为什么我认为这段代码由于一些搜索和查找错误而无法获取数据的原因。任何人都可以帮忙吗?