faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 1 people (100%) answered Yes

Entry

Showing docstrings of modules

Jul 5th, 2000 10:01
Nathan Wallace, Hans Nowak, Snippet 219, J


"""
Packages: text.docstrings;modules_and_packages
"""
"""
I just wrote this short script inspired by this post.. it's a little more
generic, but it's incomplete. feel free to use the code, post
enhancements, etc. it is limited in what it can do-- it won't work for
'os.path', for example, but it's a start.
"""
#!/usr/bin/env python
def showdoc(module):
 try:
  m = __import__(module)
 except ImportError, reason:
  print "** import error: %s" % (reason)
  return
 if hasattr(m, "__doc__") and m.__doc__ != None:
  print "-- module documentation --"
  print m.__doc__
  print "-- end module documentation --"
 print
 for item in dir(m):
  print item
  if hasattr(item, "__doc__"):
   print " %s" % (item.__doc__)
  else:
   print " %s has no doc string." % (item)
 del m
if __name__ == "__main__":
 showdoc("string")