On Thu, Nov 19, 2009 at 9:31 PM, Eric Pavey <warp...@gmail.com> wrote:
> Say I have this package layout
>
> \myPackage
>
> __init__.py
> moduleA.py
> moduleB.py
>
> Is there a way (and I'm sure there is...) to query, for a given package
> level, which modules live under it?
> I thought I could do it like so:
>
> import myPackage
> goodQualityInfo = dir(myPackage)

One way to do this is to include an __all__ attribute in __init__.p]:
__all__ = ['moduleA', 'moduleB']

Then instead of dir(myPackage) use myPackage.__all__.

The name is standard though it is usually used for a slightly different purpose:
http://docs.python.org/tutorial/modules.html#importing-from-a-package

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to