if, continuation and indentation
Tim Chase
python.list at tim.thechases.com
Thu May 27 10:10:55 EDT 2010
On 05/27/2010 07:22 AM, HH wrote:
> When I write an if statement with many conditions, I prefer to use a
> parenthesis around the whole block and get the implicit continuation,
> rather than ending each line with an escape character. Thus, using
> the example from the style guide (http://www.python.org/dev/peps/
> pep-0008/) I would write:
>
> if (width == 0 and
> height == 0 and
> color == 'red' and
> emphasis == 'strong' or
> highlight> 100):
> raise ValueError("sorry, you lose")
While it's not PEP material, I tend to use the coding standards I
learned working for Computer Sciences Corporation (10 yrs ago, so
things may have changed) that mandated 2 levels of indentation
for continued lines, turning the above into
if (width == 0 and
height == 0 and
color == 'red' and
emphasis == 'strong' or
highlight> 100):
# or the closing "):" on this line,
# aligned with the previous line
raise ValueError("sorry, you lose")
which is fairly close to Jean-Michel's proposal.
-tkc
More information about the Python-list
mailing list