在python中创建XML文档?

时间:2013-12-16 09:22:37

标签: python elementtree

尝试在Python中导入elementtree时 任何人都可以帮忙解决这个错误吗?

我没有获得任何模块:

ImportError: No module named elementtree.ElementTree

2 个答案:

答案 0 :(得分:6)

模块名称为xml.etree.ElementTree,而非elementtree.ElementTree

>>> import xml.elementtree.ElementTree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named elementtree.ElementTree
>>> import xml.etree.ElementTree
>>>

答案 1 :(得分:0)

试试这个: 如果您有cElementTree,为什么不使用它?更快!

try:
    import xml.etree.cElementTree as ET
except ImportError:
    import xml.etree.ElementTree as ET