[Tutor] How do I do this

Kalle Svensson kalle@gnupung.net
Sat, 8 Sep 2001 22:47:01 +0200


[Girish Gajwani]
> Hi All,
> 
> I was trying to get the documentation of all functions in a
> particular module, as follows:
> 
> 
> ############################################
> #! /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 substituted for each of the 
>                                # modules, functions and we will get __doc__ for 
>                                # each of these
> main()
> 
> ############################################
> 
> This does not work. How do I do this?

def main():
    for i in dir(getopt):
        try:
	    print i, getattr(getopt, i).__doc__
	except AttributeError:
	    print "getopt.%s has no __doc__ attribute" % i

seems to work.

Peace,
  Kalle
-- 
[  kalle@gnupung.net  ][ Thought control, brought to you by the WIPO! ]
[ http://gnupung.net/ ][ http://anti-dmca.org/ http://eurorights.org/ ]