List of modules available for import inside Python?

sc nospam at spamhaters.com
Sun Sep 7 16:56:54 EDT 2008


Gabriel Genellina wrote:

> En Sat, 06 Sep 2008 17:18:55 -0300, clurker <nospam at spamhaters.com>
> escribió:
> 
>> Michele Simionato wrote:
>>
>>> On Aug 28, 6:21 am, ssecorp <circularf... at gmail.com> wrote:
>>>> Is there a way to view all the modules I have available for import
>>>> from within Python?
>>>> Like writing in the interpreter:
>>>
>>> Try:
>>>
>>>>>> help()
>>> help> modules
>>> Please wait a moment while I gather a list of all available modules...
>>> <snip>
>>
>> This looks like it could be a useful tool, but when I try it
>> I get the following:
>>
>> Please wait a moment while I gather a list of all available modules...
> [...]
>>   File "/usr/local/lib/python2.5/site-packages/PIL/__init__.py", line
>>   1342,
>> in <module>
>>
>>   File "/usr/local/lib/python2.5/site-packages/PIL/__init__.py", line
>>   927,
>> in main
>>
>> UnboundLocalError: local variable 'given_files' referenced before
>> assignment
>>>>>
> 
> Unfortunately the "modules" help command actually imports all the
> available packages, and a buggy one may stop the whole process with an
> error.
> 
>> Apparently python knows about them both, but I don't know I
>> haven't introduced an incompatibility somewhere...and that PIL
>> package showing up at the tail of the errors was one of my
>> more recent additions...
> 
> If import of a package fails, the error reported is not accurate. In this
> case, probably some other package failed, that itself imported PIL. Line
> 927 in PIL/__init__.py does not exist.
> 
> A quick fix is to replace line 1854 in pydoc.py (ModuleScanner.run) with
> this one:
> 
>         for importer, modname, ispkg in
>         pkgutil.walk_packages(onerror=lambda name:None):
> 
> (the onerror argument makes it to ignore all errors)
> 

nice Gabriel, thanx!  At least now "help(); modules" gives me a beautiful
list -- I guess I'll find out what the buggy module is if/when I try
to use it...(all PIL/__init__.py is is about 15 lines of comments 
(referencing a README I can't find))

sc




More information about the Python-list mailing list