[Python-Dev] Add __exports__ to modules
Thu, 11 Jan 2001 11:38:50 -0800
On Thu, Jan 11, 2001 at 10:58:55AM -0500, Guido van Rossum wrote:
> > Please don't use __all__. At the moment, __all__ is the only way
> > to easily tell whether a particular module object really represents
> > a package, and the only way to get the list of submodule names.
> > If __all__ is overloaded to also represent exportable symbols in
> > modules, these two pieces of information will be impossible (or
> > require much ugly hackery) to obtain.
> Marc-Andre already explained that __all__ is not to be trusted.
> If you want a reasonably good test for package-ness, use the presence
> of __path__.
> For a really good test, check whether __file__ ends in __init__.py[c].
Even that isn't safe: if the module was pulled from an archive, __file__
might not get set.
Determining whether something is a package is highly dependent upon how it
was brought into the system. It is entirely possibly that you *can't* know
something represents a package.
You can get close by looking in sys.modules to look for modules "below" the
given module. But if none have been imported yet, then you're out of luck.
If you're using imputil, then you can look for __ispkg__ in the module.
Greg Stein, http://www.lyra.org/