12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

As summarized in Table 14-1, there are a variety of places to look for information on<strong>Python</strong> with generally increasing verbosity. Because documentation is such a crucialtool in practical programming, we’ll explore each of these categories in the sectionsthat follow.Table 14-1. <strong>Python</strong> documentation sourcesForm# CommentsHash-mark comments are the most basic way to document your code. <strong>Python</strong> simplyignores all the text following a # (as long as it’s not inside a string literal), so youcan follow this character with words and descriptions meaningful to programmers.Such comments are accessible only in your source files, though; to code commentsthat are more widely available, use docstrings.In fact, current best practice generally dictates that docstings are best for larger functionaldocumentation (e.g., “my file does this”), and # comments are best limited tosmaller code documentation (e.g., “this strange expression does this”). More on docstringsin a moment.The dir FunctionRole# comments In-file documentationThe dir functionLists of attributes available in objectsDocstrings: _ _doc_ _In-file documentation attached to objectsPyDoc: The help function Interactive help for objectsPyDoc: HTML reportsModule documentation in a browserStandard manual setOfficial language and library descriptionsWeb resourcesOnline tutorials, examples, and so onPublished booksCommercially available reference textsThe built-in dir function is an easy way to grab a list of all the attributes availableinside an object (i.e., its methods and simpler data items). It can be called on anyobject that has attributes. For example, to find out what’s available in the standardlibrary’s sys module, import it, and pass it to dir:>>> import sys>>> dir(sys)['_ _displayhook_ _', '_ _doc_ _', '_ _excepthook_ _', '_ _name_ _','_ _stderr_ _', '_ _stdin_ _', '_ _stdout_ _', '_getframe', 'argv','builtin_module_names', 'byteorder', 'copyright', 'displayhook','dllhandle', 'exc_info', 'exc_type', 'excepthook',...more names omitted...]<strong>Python</strong> Documentation Sources | 279

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!