In the process of learning to parse XML using Python, use the examples in the official document https://docs.python.org/2/library/xml.etree.elementtree.html to test the code as follows:
Import Xml.etree.ElementTree as Ettree = Et.parse ('/home/huayuan/code/xml.py ') root = Tree.getroot ()
Try to run, did not think unexpectedly will error:
Traceback (most recent):
File "/home/huayuan/code/xml.py", line 1, <module>
Import Xml.etree.ElementTree as ET
File "/home/huayuan/code/xml.py", line 1, <module>
Import Xml.etree.ElementTree as ET
Importerror: No module named Etree. ElementTree
[Finished in 0.1s with exit code 1]
Check Python's library path/usr/lib/python2.7/xml/etree and find that the xml.etree.Element package is normal, such as:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/4A/0C/wKioL1QhiuThkrS3AAClZJ0PNA4158.jpg "title=" Python.png "alt=" Wkiol1qhiuthkrs3aaclzj0pna4158.jpg "/>
Reading the wrong hint is import xml.etree.ElementTree as ET this sentence has a problem, so try to make different changes to it, the results will not help.
Finally can only resort to Baidu, search for a long time, found that netizens seem to have busty smooth, almost no one mentioned that there is such a situation.
Later, at last in a humble corner to see this sentence: do not use XML as the file name.
I just named the code file as a xml.py, immediately renamed, and then run. The result is still not, careful investigation, found that the generated XML.PYC file also exists, it may be caused by the impact, deleted the retry, and finally run smoothly.
Summarize:
Looking back, this can be said to be a low-level error, Python refers to the package should be first in the code file in the folder to find, the file name of xml.py, import xml.etree.Element This sentence in the current folder to find their own source files, their written xml.py inside there is no etree.element these modules, of course, is to error.
This article is from the "Free Self" blog, please be sure to keep this source http://hhuayuan.blog.51cto.com/1630327/1557536
Python XML No module named Etree. ElementTree