[Python-Dev] stupid package tricks (original) (raw)
Phillip J. Eby pje at telecommunity.com
Mon Dec 12 22:29:36 CET 2005
- Previous message: [Python-Dev] stupid package tricks
- Next message: [Python-Dev] ElementTree in stdlib
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 10:03 PM 12/12/2005 +0100, Fredrik Lundh wrote:
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?
I'd suggest:
import _xmlplus
_xmlplus.__path__.extend(__path__)
sys.modules[__name__] = _xmlplus
This ensures that any modules or packages inside 'xml' that aren't explicitly overridden by _xmlplus will still be available.
- Previous message: [Python-Dev] stupid package tricks
- Next message: [Python-Dev] ElementTree in stdlib
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]