【问题标题】:How to fix Python error importing ElementTree?如何修复导入 ElementTree 的 Python 错误?
【发布时间】:2010-11-16 08:51:49
【问题描述】:

我开始学习 python,在这里我尝试使用 ElementTree 从 xml 文件中读取:

import sys
from elementtree.ElementTree import ElementTree

doc = ElementTree(file="test.xml")
doc.write(sys.stdout)  

但是我得到这个错误: 文件“my_xml.py”,第 2 行,在 从元素树.元素树导入元素树 ImportError:没有名为 elementtree.ElementTree 的模块

我确实在 /usr/lib/python2.6/xml/etree/... 中有 lib 文件 我做错了什么?

非常感谢您的帮助:)

【问题讨论】:

    标签: python xml


    【解决方案1】:

    应该是:

    from xml.etree.ElementTree import ElementTree
    

    更多信息请访问Python docs。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-10
      • 2020-02-03
      • 1970-01-01
      • 2018-11-18
      • 1970-01-01
      • 1970-01-01
      • 2022-06-28
      • 1970-01-01
      相关资源
      最近更新 更多