Using SimpleXMLTreeBuilder in elementtree
Question: I have been developing an application with django and elementtree and while
deploying it to the production server i have found out it is running python
2.4. I have been able to bundle elementtree but now i am getting the error:

    
    
    "No module named expat; use SimpleXMLTreeBuilder instead"
    

Unfortunately i cannot upgrade python so im stuck with what i got. How do i
use SimpleXMLTreeBuilder as the parser and/or will i need to rewrite code?


Answer: If you have third party module that wants to use ElementTree (and
XMLTreeBuilder by dependency) you can change ElementTree's XMLTreeBuilder
definition to the one provided by SimpleXMLTreeBuilder like so:

    
    
    from xml.etree import ElementTree # part of python distribution
    from elementtree import SimpleXMLTreeBuilder # part of your codebase
    ElementTree.XMLTreeBuilder = SimpleXMLTreeBuilder.TreeBuilder
    

Now ElementTree will always use the SimpleXMLTreeBuilder whenever it's called.

See also: <http://groups.google.com/group/google-
appengine/browse_thread/thread/b7399a91c9525c97>

