[Tutor] How do I do this

dman dsh8290@rit.edu
Sat, 08 Sep 2001 16:38:19 -0400


On Sun, Sep 09, 2001 at 01:59:01AM +0530, Girish Gajwani wrote:
| Hi All,
| 
| I was trying to get the documentation of all functions in a
| particular module, as follows:

Take a look at pydoc -- all the hard work has been done for you.

| ############################################
| #! /usr/bin/env  python
| 
| """Documentation comes like this.
| 
| this will be the documentation for this file(module)
| 
| """
| import sys, os, string, getopt
| 
| def main():
|   for i in dir(getopt):
|     print i, getopt.i.__doc__  # assuming i will be
                     
This line is the problem.  When you write 
    foo.bar
in the source code 'foo' is the name of an object and 'bar' is the
name of its member.  As you have it here you are printing each object
of the getopt module by a *reference* to it ('i'), then trying to get
the member of the getopt module *named* i, which probably doesn't
exist.

Instead try this

    print i , i.__doc__

HTH,
-D