Importing dynamically loaded modules (in packages)?
Gordon McMillan
gmcm at hypernet.com
Thu May 2 12:09:37 EDT 2002
holger krekel wrote:
> [Steve Holden]
[snip]
>> A package is a directory containing an __init__.py file.
>
> And that's where it starts to fall out of pythons object world.
> There is no 'directory'-object.
No, but there's a PKG_DIRECTORY type-code (see the imp module).
>> When the package is
>> imported (which mjust happen before any submodules or subpackages can
>> be imported) the __init__.py file is executed.
>
> The next filesystem-dependence not related to python's object
> structure.
The __init__ name is special.
No, none of this is done in an object model exposed to Python (the
language). If you want that, see
http://www.mcmillan-inc.com/iu.html
Note that "a.b.c" means something different in an import statement
than it does anywhere else. Anywhere else, it's strictly attribute
access. Python's implementation of import provides a mapping to
the filesystem, but since it's hookable, you can map it to any
structure (you only need a subset of the normal tree-navigation
rules).
Granted, you'll have to look at the implementation to figure out
how the mapping-to-filesystem actually works. iu.py provides a
(complete as far as I know) implementation in pure Python.
-- Gordon
http://www.mcmillan-inc.com/
More information about the Python-list
mailing list