access to submodules

Peter Otten __peter__ at web.de
Wed Jul 19 12:20:17 EDT 2006


TG wrote:

> okay,
> 
> so only when I have inside __init__.py
> 
> __all__ = ["core"]
> 
> this works
> 
> ?> from tom import *
> ?> help(core)
> 
> but (in a brand new interpretor)
> 
> ?> import tom
> ?> help(tom.core)
> 
> AttributeError: 'module' object has no attribute 'core'
> 
> got it. But ...
> 
> ?> import numpy
> ?> help(numpy.core)
> 
> this will work, even if core is a subpackage of numpy. and i don't have
> to explicitly import numpy.core.
> 
> I must be missing something ... :-/

numpy does the equivalent of 

import core

in its __init__.py

"""
Help on method __call__ in module numpy._import_tools:

__call__(self, *packages, **options) unbound
numpy._import_tools.PackageLoader method
    Load one or more packages into parent package top-level namespace.

    Usage:

       This function is intended to shorten the need to import many of
       subpackages, say of scipy, constantly with statements such as

       import scipy.linalg, scipy.fftpack, scipy.etc...

       Instead, you can say:

         import scipy
         scipy.pkgload('linalg','fftpack',...)
"""

Peter



More information about the Python-list mailing list