Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
853 views
in Technique[技术] by (71.8m points)

import - Python 2.5.4 - ImportError: No module named etree.ElementTree

I'm running Python 2.5.4 on Windows and I keep getting an error when trying to import the ElementTree or cElementTree modules. The code is very simple (I'm following a tutorial):

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()

I get the error message when I run it from the cmd or but not when I directly try it from the Python interpreter.

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

Also, I checked and the module is there in C:Python25Libxmletree

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Because your original file name is C:xml.py

Change the file name to any other name


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...