Listing all python modules robustly

Brian Brian.Mingus at
Tue Mar 31 18:13:00 CEST 2009

Turns out that the Twisted framework provides better introspective support
than standard python, so problem solved!

On Tue, Mar 31, 2009 at 8:12 AM, Brian <Brian.Mingus at> wrote:

> I've used the C api to write a method that can call any python module
> function. I would like to extend the interface to allow dynamically listing
> all python modules, and for a given module all functions, and for a given
> function all argument types and the return types if possible.
> Starting with the modules, I came up with this bit of code:
> from pkgutil import walk_packages;
> modules=[]
> modules = [modules.append(item[1]) for item in walk_packages()]
> I then took this to my various systems for testing. It works fine on OSX
> and one of my Ubuntu boxes, but two of the Ubuntu boxes fail, each with a
> different error message.  The failure is due to python importing every
> single module and some of the modules failing. One example is the
> UniConverter package - towards the end of it calls sys.exit(0)
> which kills the interpreter completely.
> I've spent a ton of time trying to rewrite walk_packages to be robust to
> failure, but so far without luck. Any advice is appreciated.
> /Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list