Finding a module's sub modules at runtime
Robert Kern
robert.kern at gmail.com
Mon Apr 2 20:33:18 EDT 2007
Joshua J. Kugler wrote:
> 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?
No, 2.5. The documentation is not up to date. Read the source.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list