[Python-Dev] stupid package tricks

Fredrik Lundh fredrik at pythonware.com
Mon Dec 12 22:03:53 CET 2005


the xml/__init__.py file contains a cute little hack that overrides
the *entire* xml subtree with stuff from PyXML, if available.

the code basically does

    import _xmlplus
    sys.modules[__name__] = _xmlplus

(exception handling and version checks not shown).

however, this means that as things are right now, xml.etree will
simply disappear if the user has PyXML on the machine.

what's the best way to fix this?  the obvious fix is of course to do
something like

    import _xmlplus
    import xml.etree
    _xmlplus.etree = xml.etree
    sys.modules[__name__] = _xmlplus

but I have to admit that I'm no expert on package internals, so I
might be missing something here.  will the above solution work in
all cases?  is there some better way to do it?

</F>





More information about the Python-Dev mailing list