Test Your Knowledge: Answers

 

 
  1. Documentation strings (docstrings) are considered best for larger, functional documentation, describing the use of modules, functions, classes, and methods in your code. Hash-mark comments are today best limited to micro-documentation about arcane expressions or statements. This is partly because docstrings are easier to find in a source file, but also because they can be extracted and displayed by the PyDoc system.
  2. You can see docstrings by printing an object’s __doc__ attribute, by passing it to PyDoc’s help function, and by selecting modules in PyDoc’s GUI search engine in client/server mode. Additionally, PyDoc can be run to save a module’s documentation in an HTML file for later viewing or printing.
  3. The built-in dir(X) function returns a list of all the attributes attached to any object.
  4. Run the PyDoc GUI interface, leave the module name blank, and select “open browser”; this opens a web page containing a link to every module available to your programs.
  5. Mine, of course. (Seriously, the Preface lists a few recommended follow-up books, both for reference and for application tutorials.)