showing help(M) when running module M standalone

Dan Sommers me at privacy.net
Sat Jul 30 11:40:19 EDT 2005


On Sat, 30 Jul 2005 17:04:50 +0200,
Chris <c at cdot.de> wrote:

> hello,
> I have a small module which only contains some utility functions. when
> running this standalone I would like to show the module docs and each
> function docs, as if doing

> 	import M
> 	help(M)

> I came up with the following but I reckon there is a much simpler way?

> if __name__ == '__main__':
>      print __doc__
>      print "\nFUNCTIONS:\n"
>      for x in __all__:
>          print x
>          exec "print " + x + ".__doc__"

> Works but does not seem right using exec for such a task.

So don't use exec.

> any hint would be great!

    for x in __all__:
        print x.__doc__

HTH,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>



More information about the Python-list mailing list