开发者

How to fix Python error importing ElementTree?

开发者 https://www.devze.com 2023-01-25 13:01 出处:网络
I\'m beginning to learn python and here I\'m trying to read from an xml file using ElementTree: import sys

I'm beginning to learn python and here I'm trying to read from an xml file using ElementTree:

import sys
from elementtree.ElementTree import ElementTree

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

However I get this error: File "my_xml.py", line 2, in from elementtree.ElementTree import ElementTree ImportError: No module named elementtree.ElementTree

I do have lib files in /usr/lib/python2.6/xml/etree/... W开发者_StackOverflowhat am I doing wrong?

Thanks a lot for your help :)


It should be:

from xml.etree.ElementTree import ElementTree

More information on this can be found at the Python docs.

0

精彩评论

暂无评论...
验证码 换一张
取 消