[Python-Dev] elementtree in stdlib

Trent Mick trentm at ActiveState.com
Thu Apr 6 21:18:40 CEST 2006


[Martijn Faassen wrote]
> I.e., this in ElementTree:
> ...

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475126
import ElementTree from everywhere 

    try:
        import xml.etree.ElementTree as ET # in python >=2.5
    except ImportError:
        try:
            import cElementTree as ET # effbot's C module
        except ImportError:
            try:
                import elementtree.ElementTree as ET # effbot's pure Python module
            except ImportError:
                try:
                    import lxml.etree as ET # ElementTree API using libxml2
                except ImportError:
                    import warnings
                    warning.warn("could not import ElementTree "
                                 "(http://effbot.org/zone/element-index.htm)")
                    # Or you might just want to raise an ImportError here.

    # Use ET.Element, ET.ElementTree, etc...


That is the current state.

Trent

-- 
Trent Mick
TrentM at ActiveState.com


More information about the Python-Dev mailing list