Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def importEtree():
- try:
- from lxml import etree
- print("running with lxml.etree")
- except ImportError:
- try:
- # Python 2.5
- import xml.etree.cElementTree as etree
- print("running with cElementTree on Python 2.5+")
- except ImportError:
- try:
- # Python 2.5
- import xml.etree.ElementTree as etree
- print("running with ElementTree on Python 2.5+")
- except ImportError:
- try:
- # normal cElementTree install
- import cElementTree as etree
- print("running with cElementTree")
- except ImportError:
- try:
- # normal ElementTree install
- import elementtree.ElementTree as etree
- print("running with ElementTree")
- except ImportError:
- print("Failed to import ElementTree from any known place")
- importEtree()
- tree = etree.parse('hero.entity')
- root = tree.getroot()
- print root
- print tree
- :::::::OUTPUT:::::::
- running with cElementTree on Python 2.5+
- Traceback (most recent call last):
- File "C:\Users\echelon\Desktop\python\XLMtest.py", line 32, in <module>
- tree = etree.parse('hero.entity')
- NameError: name 'etree' is not defined
- >>>
Add Comment
Please, Sign In to add comment