Google Python Style Guide
google-styleguide.googlecode.com
google-styleguide.googlecode.com
Google (original formatting):
BE CONSISTENT.
PEP8: A Foolish Consistency is the Hobgoblin of Little MindsThe quote from PEP8 translates in my mind to "be consistent if it's worth it".
These policies are not orthogonal. You can't satisfy both in all cases.
This style guide looks like a superset of PEP 8 -- where PEP 8 describes what Python code should look like, this guide goes through every Python feature and lays out exactly where a sizable group of top-notch Python hackers were willing to draw the line on maintainability vs. whipupitude for large, long-running projects.
I had this notion it formerly was 2 spaces (too little, IMH-once-bitten-O). Anyone know when it changed, if it did ?
P.S. In http://groups.google.com/group/django-developers/msg/f6a86d1... , back in Aug.2008, GvR says "Most of it [Google's unpublished internal Python style] is simply PEP-8 with 2-space indents."
(I dislike 2 spaces, once bitten by missing an indentation bug. I try to stick to 80 columns - both for print and side-by-side on screen - and think that more than 4 or 5 levels of indentation is "doing it wrong".)
Ruby has standardized on 2 spaces.
I've noticed in my own experience that 2 spaces is not enough to read python quickly. 2 spaces works fine in ruby because whitespace isn't significant, you can find the end of a control structure by looking for the end keyword.
Which is a style guide for the "SoC framework, and Melange web applications", updated Jun.2009; it does specify 2 spaces, duly noted as a difference from PEP-8.
/me hides before the flames start :)
import foo
from foo import bar
from foo.bar import baz
from foo.bar import Quux
from Foob import ar
That seems kind of time consuming...Sorting makes it easier to recognize a common grouping of imports (e.g. some recurring functionality that requires three particular modules) without inspecting the words carefully.
I hate that. should inherit from StandardError IMNSHO. It's a quibble though and a pointless one until the standard library follows that. (which it never will...)
> Use the "implicit" false if at all possible.
Is so wrong, for the listed caveat reasons and more. It's the opposite of readability to me. Similar issues with the use default iterators. If my loop is expecting a dictionary and to iterate over it's keys I really want the "foo has no method keys" error rather than looping over a list and creating hard to discover/understand bug.
x = '%s, %s!' % (imperative, expletive)
A decidedly familiar sentence structure...