[Edu-sig] import mechanism questions

Kirby Urner urnerk@qwest.net
Sun, 12 Jan 2003 18:01:54 -0800


>
>Ideas appreciated.
>
>Art

Are you fully exploiting the 'package' feature by using
the top level __init__.py in /PyGeo to bring in everything
a user might need?

It seems to me that ideally you'd want PyGeo under
site-packages, with an

 >>> import PyGeo

giving the user access to all top-level tools needed to
exploit the package.  The option to go:

 >>> from PyGeo import *

would be there too (up to the user to opt for that form).
You'd use __init__.py at the top level to pull in whatever
you need from any of the subdirectories.

As to your specific question, as I understand the docs,
import foo treats foo as a key string into a lookup table
of accessible module objects (of type 'module'), which
table you may expose as sys.modules.  Failing here,
Python initiates a platform-specific search routine
paying attention to the path (sys.path).

By defining Complex = Geometry.Complex, you are not adding
anything to this lookup table (nor to the path).  However,
you may do so explicitly:

 >>> sys.modules['Complex'] = Geometry.Complex
 >>> import Complex

will work.

Kirby