[Python-Dev] python package

M.-A. Lemburg mal@lemburg.com
Sat, 13 Jul 2002 19:58:38 +0200


Gordon McMillan wrote:
> On 12 Jul 2002 at 16:46, Michael McLay wrote:
> 
> 
>>... it might be reasonable to move all standard
>>distribution names into a single top level namespace
>>and grandfather the existing top level names into
>>the top level namespace for the remainder of
>>the 2.x series. 
> 
> 
> Getting
>  from <toplevelname> import urllib
> and 
>  import urllib
> 
> to return the same (is, not equals) object will
> require very delicate surgery on some very difficult
> code. And without it, most non-trivial scripts will
> break in very mysterious ways.

Not really. The following code does all it takes to
make this work for e.g. having 'import DateTime'
and 'from mx import DateTime' provide the same
symbols:

# Redirect all imports to the corresponding mx package
def _redirect(mx_subpackage):
     global __path__
     import os,mx
     __path__ = [os.path.join(mx.__path__[0],mx_subpackage)]
_redirect('DateTime')

# Now load all important symbols
from mx.DateTime import *
from mx.DateTime import __version__,_DT,_DTD

The module objects would be different, but that's just
about it.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
_______________________________________________________________________
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting:                               http://www.egenix.com/
Python Software:                    http://www.egenix.com/files/python/