getting list of all available modules

B

Benjamin Rutt

I note that the help() function of interactive python can determine
all available modules:

[rutt@akron ~]$ python
Python 2.4 (#1, Mar 31 2005, 15:26:02)
[GCC 3.2.3 (Debian)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
[...]

help> modules

Please wait a moment while I gather a list of all available modules...

BaseHTTPServer bisect linuxaudiodev shelve
Bastion bsddb (package) locale shlex
BicycleRepairMan_Idle cPickle logging (package) shutil
CDROM cStringIO macpath signal
CGIHTTPServer calendar macurl2path site
Canvas cgi mailbox smtpd
ConfigParser cgitb mailcap smtplib

[...]

I want to do the same (get all such modules in a python list); how can
I do so? Or where is the code for the REPL for help() itself so I can
find out myself?

This is to build a code introspection tool BTW. Thanks,
 
C

Christos TZOTZIOY Georgiou

I note that the help() function of interactive python can determine
all available modules:

I want to do the same (get all such modules in a python list); how can
I do so? Or where is the code for the REPL for help() itself so I can
find out myself?

Try browsing the site.py file in your standard lib directory; there's a
_Helper class that is what you are looking for. help is an instance of
_Helper, as you can see by typing in the interactive prompt:
<class 'site._Helper'>
 
P

Peter Otten

Benjamin said:
I want to do the same (get all such modules in a python list); how can
I do so?  Or where is the code for the REPL for help() itself so I can
find out myself?

Get hold of the Python source code and grep for some (hopefully) selective
piece of text. In the case of help() you are lucky as it is implemented in
Python, and therefore searching the stdlib will do:

$ find /usr/local/lib/python2.4 -name \*.py |xargs grep "Please wait"
/usr/local/lib/python2.4/pydoc.py:please wait a moment while I gather a list
of all available modules...

Looking into that file, a suspiciously named ModuleScanner class is right
over there. Now what is your excuse for not finding it yourself in the
first place? You seem to be on Linux, so "That's not how I do it with
Visual Basic" can't be it :)

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top