Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python和specyfic xml文件问题,无法从getchildren()获取值_Python_Xml - Fatal编程技术网

Python和specyfic xml文件问题,无法从getchildren()获取值

Python和specyfic xml文件问题,无法从getchildren()获取值,python,xml,Python,Xml,我试图编写一个脚本,它可以更改xml文件中的值,但该文件的构造非常困难。我需要从xml行“r2dd”中精确编辑值:10.0;10.0;26.0;14.0. 顺便说一句,我不能将它们赋给变量 xml文件: <?xml version="1.0" encoding="UTF-8"?> <objects fpmi.archive.type="components" framework.version="7.9.8.2018060714" fpmi.version="9.9.8.0"

我试图编写一个脚本,它可以更改xml文件中的值,但该文件的构造非常困难。我需要从xml行“r2dd”中精确编辑值:10.0;10.0;26.0;14.0. 顺便说一句,我不能将它们赋给变量

xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<objects fpmi.archive.type="components" framework.version="7.9.8.2018060714" fpmi.version="9.9.8.0" timestamp="Thu Sep 27 15:00:19 CEST 2018">
  <arraylist len="0"/>
<c cls="com.inductiveautomation.factorypmi.application.components.template.TemplateHolder">
  <c-comm>
    <p2df>26.0;14.0</p2df>
    <r2dd>10.0;10.0;26.0;14.0</r2dd>
    <str>X123_C61023</str>
    <lc>10.0;10.0;16;0;0.7058824;1.3333334</lc>
  </c-comm>
  <c-c m="setParameterValues" s="1;java.util.Map">
    <o cls="java.util.HashMap">
      <o-c m="put" s="2;O;O">
        <str>tagPath</str>
        <str>X123_X123_C61023</str>
      </o-c>
    </o>
  </c-c>
  <c-c m="setTemplatePath" s="1;str">
    <str>[network]premium/aw1/tags/monitors</str>
  </c-c>
</c>
请有人帮我把这个值从“r2dd”xml行分配给一个变量好吗? 此时,控制台仅显示:

    other_value=other.get('type')
AttributeError: 'list' object has no attribute 'get'
values :  [<Element 'p2df' at 0x035753C0>, <Element 'r2dd' at 0x03575410>, <Element 'str' at 0x03575438>, <Element 'lc' at 0x03575488>]
other\u value=other.get('type'))
AttributeError:“list”对象没有属性“get”
值:[,,]
但没有价值观。请帮忙


(我只能使用getchildren()访问此元素,但这是一种错误的方法)。

我认为这是因为您没有索引返回getchildren的列表

other=x.find('c-comm').getchildren()
print('values : ', other)
other_value=other.get('type')
正如您在本部分中看到的,您将子变量列表存储在other中,然后将此变量视为子变量。并且可以在您发布的印刷品中看到这一点:

values :  [<Element 'p2df' at 0x035753C0>, <Element 'r2dd' at 0x03575410>, <Element 'str' at 0x03575438>, <Element 'lc' at 0x03575488>]
值:[,,]

因此,您正在查找此列表的第二个元素。

这是否回答了您的问题?
values :  [<Element 'p2df' at 0x035753C0>, <Element 'r2dd' at 0x03575410>, <Element 'str' at 0x03575438>, <Element 'lc' at 0x03575488>]