getting list of all available modules

Discussion in 'Python' started by Benjamin Rutt, Jun 21, 2005.

  1. 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
    Benjamin Rutt, Jun 21, 2005
    #1
    1. Advertising

  2. On Tue, 21 Jun 2005 01:33:06 GMT, rumours say that Benjamin Rutt
    <> 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...
    Christos TZOTZIOY Georgiou, Jun 21, 2005
    #2
    1. Advertising

  3. Benjamin Rutt

    Peter Otten Guest

    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
    Peter Otten, Jun 21, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ssecorp
    Replies:
    14
    Views:
    737
    Fredrik Lundh
    Sep 10, 2008
  2. John [H2O]
    Replies:
    0
    Views:
    280
    John [H2O]
    Oct 28, 2008
  3. harryos

    how to list all installed modules

    harryos, Feb 18, 2009, in forum: Python
    Replies:
    3
    Views:
    617
    harryos
    Feb 19, 2009
  4. Tim Michelsen

    creating a list of all imported modules

    Tim Michelsen, Mar 10, 2009, in forum: Python
    Replies:
    5
    Views:
    250
    John Machin
    Mar 10, 2009
  5. Fei Liu
    Replies:
    2
    Views:
    1,837
Loading...

Share This Page