Finding a module's sub modules at runtime
Joshua J. Kugler
joshua at eeinternet.com
Mon Apr 2 20:18:56 EDT 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?
http://docs.python.org/lib/module-pkgutil.html 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:
http://mail.python.org/pipermail/python-checkins/2006-April/051452.html and
add it to my module. :)
Thanks for the pointer!
j
--
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/ ID 0xDB26D7CE
--
Posted via a free Usenet account from http://www.teranews.com
More information about the Python-list
mailing list