Listing all python modules robustly

Brian Brian.Mingus at colorado.edu
Tue Mar 31 10:12:15 EDT 2009


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/c9ac1243/attachment.html>


More information about the Python-list mailing list