Listing all python modules robustly

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


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

http://twistedmatrix.com/documents/8.2.0/api/twisted.python.modules.html#walkModules

On Tue, Mar 31, 2009 at 8:12 AM, Brian <Brian.Mingus at colorado.edu> 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 __init__.py 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: <http://mail.python.org/pipermail/python-list/attachments/20090331/9a75db91/attachment.html>


More information about the Python-list mailing list