google的python编码规范
Google Python Style Guide
Revision 2.19
Amit Patel
Antoine Picard
Eugene Jhong
Jeremy Hylton
Matt Smart
Mike Shields
Each style point has a summary for which additional information is available by toggling the accompanying
arrow button that looks this way:?. You may toggle all summaries with the big arrow button:
? Toggle all summaries
Table of Contents
Python
Language
Rules
pychecker Imports Packages Exceptions Global variables Nested/Local/Inner Classes and
FunctionsList Comprehensions Default Iterators and Operators Generators Lambda
FunctionsDefault Argument Values Properties True/False evaluations Deprecated
Language FeaturesLexical Scoping Function and Method Decorators Threading Power
Features
Python
Style Rules
Semicolons Line length Parentheses Indentation Blank Lines Whitespace Python
InterpreterComments Classes Strings TODO Comments Imports
formatting Statements Access Control NamingMain
Important Note
Displaying Hidden Details in this Guide
link▽
This style guide contains many details that are initially hidden from view. They are marked by the
triangle icon, which you see here on your left. Click it now. You should see "Hooray" appear
below.
Hooray! Now you know you can expand points to get more details. Alternatively, there's a "toggle
all" at the top of this document.
Background
Python is the main scripting language used at Google. This style guide is a list of dos and don'ts
for Python programs.
To help you format code correctly, we've created a settings file for Vim. For Emacs, the default
settings should be fine.
Python Language Rules
pychecker
link▽
Run pychecker over your code.
Definition:PyChecker is a tool for finding bugs in Python source code. It finds problems that are
typically caught by a compiler for less dynamic languages like C and C++. It is similar to lint.
Because of the dynamic nature of Python, some warnings may be incorrect; however, spurious
warnings should be fairly infrequent.
Pros