fork(3) download
  1. """Cheap and simple API helper
  2.  
  3. This program is part of "Dive Into Python", a free Python book for
  4. experienced programmers. Visit http://d...content-available-to-author-only...n.org/ for the
  5. latest version.
  6. """
  7. __author__ = "Mark Pilgrim (mark@diveintopython.org)"
  8. __version__ = "$Revision: 1.3 $"
  9. __date__ = "$Date: 2004/05/05 21:57:19 $"
  10. __copyright__ = "Copyright (c) 2001 Mark Pilgrim"
  11. __license__ = "Python"
  12.  
  13. # While this is a good example script to teach about introspection,
  14. # in real life it has been superceded by PyDoc, which is part of the
  15. # standard library in Python 2.1 and later.
  16. #
  17. # Your IDE may already import the "help" function from pydoc
  18. # automatically on startup; if not, do this:
  19. #
  20. # >>> from pydoc import help
  21. #
  22. # The help function in this module takes the object itself to get
  23. # help on, but PyDoc can also take a string, like this:
  24. #
  25. # >>> help("string") # gets help on the string module
  26. # >>> help("apihelper.help") # gets help on the function below
  27. # >>> help() # enters an interactive help mode
  28. #
  29. # PyDoc can also act as an HTTP server to dynamically produce
  30. # HTML-formatted documentation of any module in your path.
  31. # That's wicked cool. Read more about PyDoc here:
  32. # http://w...content-available-to-author-only...p.com/pub/a/python/2001/04/18/pydoc.html
  33.  
  34. def info(object, spacing=10, collapse=1):
  35. """Print methods and doc strings.
  36.  
  37. Takes module, class, list, dictionary, or string."""
  38. methodList = [e for e in dir(object) if callable(getattr(object, e))]
  39. processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
  40. print "\n".join(["%s %s" %
  41. (method.ljust(spacing),
  42. processFunc(str(getattr(object, method).__doc__)))
  43. for method in methodList])
  44.  
  45. if __name__ == "__main__":
  46. print help.__doc__
  47.  
Success #stdin #stdout 0.03s 44680KB
stdin
Standard input is empty
stdout
Define the builtin 'help'.
    This is a wrapper around pydoc.help (with a twist).