Finding a module's sub modules at runtime

Joshua J. Kugler joshua at
Tue Apr 3 02:18:56 CEST 2007

On Thursday 29 March 2007 17:58, Alex Martelli wrote:
> Sure, pydoc (which help calls under the code) does that, with a nice mix
> of inspect, os, and pkgutil.iter_modules calls.  pkgutil.iter_modules
> may in fact be most of what you need:
>>>> help(pkgutil.iter_modules)
> Help on function iter_modules in module pkgutil:
> iter_modules(path=None, prefix='')
>     Yields (module_loader, name, ispkg) for all submodules on path,
>     or, if path is None, all top-level modules on sys.path.
>     'path' should be either None or a list of paths to look for
>     modules in.
>     'prefix' is a string to output on the front of every module name
>     on output.

OK, that looks nice...but what version of Python is that? only shows one function (and
that's 2.5) and my python 2.4 installation is similarly lacking an
iter_modules() function for the pkgutil module.  Is this a 2.6 thing?

Suppose I could just copy the code from here: and
add it to my module. :)

Thanks for the pointer!


Joshua Kugler
Lead System Admin -- Senior Programmer
PGP Key:  ID 0xDB26D7CE

Posted via a free Usenet account from

More information about the Python-list mailing list