gpt4 book ai didi

Python 2.5.4 - ImportError : No module named etree. ElementTree

转载 作者:太空狗 更新时间:2023-10-29 19:30:13 25 4
gpt4 key购买 nike

我在 Windows 上运行 Python 2.5.4,但在尝试导入 ElementTree 或 cElementTree 模块时,我不断收到错误消息。代码非常简单(我正在学习教程):

import xml.etree.ElementTree as xml

root = xml.Element('root')
child = xml.Element('child')
root.append(child)
child.attrib['name'] = "Charlie"
file = open("test.xml", 'w')
xml.ElementTree(root).write(file)
file.close()

当我从 cmd 运行它时,或者当我直接从 Python 解释器尝试它时,我没有收到错误消息。

Traceback (most recent call last):  
File "C:\xml.py", line 31, in <module>
import xml.etree.ElementTree as xml
File "C:\xml.py", line 31, in <module>
import xml.etree.ElementTree as xml
ImportError: No module named etree.ElementTree

另外,我检查了一下,模块在 C:\Python25\Lib\xml\etree 中

最佳答案

因为你原来的文件名是C:\xml.py

将文件名更改为任何其他名称

关于Python 2.5.4 - ImportError : No module named etree. ElementTree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3073033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com