Sidebar Discussion:

Python Tip: Harnessing pydoc for Effective Help During Development

We’ll work though some examples that illustrate the use of the twitter package, but just in case you're ever in a situation where you need some help (and you will be), it's worth remembering that you can always skim the documentation for a package (its pydoc ) in a few different ways. Outside of a Python shell, running pydoc in your terminal on a package in your PYTHONPATH is a nice option. For example, on a Linux or Mac system, you can simply type pydoc twitter in a terminal to get the package-level documentation, whereas pydoc twitter.Twitter provides documentation on the Twitter class included with that package. On Windows systems, you can get the same information, albeit in a slightly different way, by executing pydoc as a package. Typing python -mpydoc twitter.Twitter , for example, would provide information on the twitter.Twitter class. If you find yourself reviewing the documentation for certain modules often, you can elect to pass the -w option to pydoc and write out an HTML page that you can save and bookmark in your browser.

However, more than likely, you'll be in the middle of a working session when you need some help. The built-in help function accepts a package or class name and is useful for an ordinary Python shell, whereas IPython users can suffix a package or class name with a question mark to view inline help. For example, you could type help(twitter) or help(twitter.Twitter) in a regular Python interpreter, while you could use the shortcut twitter? or twitter.Twitter? in IPython or IPython Notebook.

It is highly recommended that you adopt IPython as your standard Python shell when working outside of IPython Notebook because of the various convenience functions, such as tab completion, session history, and "magic functions," that it offers. Recall that Appendix A, Information About This Book's Virtual Machine Experience provides minimal details on getting oriented with recommended developer tools such as IPython.