By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,008 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

getting list of all available modules

P: n/a
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()


[...]

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,
--
Benjamin Rutt
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 21 Jun 2005 01:33:06 GMT, rumours say that Benjamin Rutt
<ru****@osu.edu> might have written:
I note that the help() function of interactive python can determine
all available modules:
<snip>
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:
type(help)

<class 'site._Helper'>

--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
Jul 19 '05 #2

P: n/a
Benjamin Rutt wrote:
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

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.