【问题标题】:AttributeError: module 'xml.etree.ElementTree' has no attribute 'ElimentTree'AttributeError:模块“xml.etree.ElementTree”没有属性“ElimentTree”
【发布时间】:2021-11-27 14:17:05
【问题描述】:

我正在尝试从 xml 文档中删除一个元素,但出现错误 :

Traceback (most recent call last):
  File "C:/Ashok/del_element_tree_country_2.py", line 25, in <module>
    tree = ET.ElimentTree(root)
AttributeError: module 'xml.etree.ElementTree' has no attribute 'ElimentTree'

我的代码是:

import xml.etree.ElementTree as ET

tree = ET.ElementTree(file='C:\\Ashok\\sample.xml')

root = tree.getroot()

DisabledFeatureListForCountry = root.find('.//DisabledFeatureListForCountry')

for DisabledFeatureDetails in DisabledFeatureListForCountry.findall('DisabledFeatureDetails'):
    _id = DisabledFeatureDetails.find('Country')
    if (_id.text == "Australia"):
        DisabledFeatureListForCountry.remove(DisabledFeatureDetails)

tree = ET.ElimentTree(root)

with open(filename, "wb") as fileupdate:
    trre.write(fileupdate)

提前致谢

【问题讨论】:

    标签: python xml elementtree


    【解决方案1】:

    您的错误来自这一行:

    tree = ET.ElimentTree(root)
    

    将其替换为以下行:

    tree = ET.ElementTree(root)
    

    【讨论】:

      猜你喜欢
      • 2018-04-14
      • 2019-02-18
      • 1970-01-01
      • 2020-01-01
      • 2019-07-20
      • 2021-11-05
      • 2021-11-04
      • 2021-02-23
      相关资源
      最近更新 更多