[Tutor] all methods in a module

Kent Johnson kent37 at tds.net
Fri May 27 14:15:07 CEST 2005


Johan Meskens CS3 jmcs3 wrote:
> my question is
> " how can i loop through all the methods in a module 
>   and print out their '__doc__' content ?
> 
> 
>>>>for d in dir( random ):
> 
> 	print random.???d???.__doc__

         print getattr(random, d).__doc__

in general you should be prepared to catch AttributeErrors (for items that don't have __doc__ 
attributes) but for random you are OK.

BTW dir() will show all attributes, not just methods.

You might want to try help(random) as well...

Kent



More information about the Tutor mailing list