if, continuation and indentation
HH
henrikho at gmail.com
Thu May 27 12:45:55 EDT 2010
On May 27, 11:37 am, Alain Ketterlin <al... at dpt-info.u-strasbg.fr>
wrote:
> HH <henri... at gmail.com> writes:
> > if (width == 0 and
> > height == 0 and
> > color == 'red' and
> > emphasis == 'strong' or
> > highlight > 100):
> > raise ValueError("sorry, you lose")
>
> I prefer to see the "and" at the beginning of continuation lines, and
> usually group related items. I never mix operators without putting
> explicit parentheses. Something like:
>
> if ( width == 0 and height == 0
> and color == 'red'
> and ( emphasis == 'strong' or highlight > 100 ) ):
> raise ValueError("sorry, you lose")
Thanks for all suggestions! I like this solution a lot.
I agree with your statement about mixed operators and explicit
parentheses -- expecially since the eye/brain parser often does it
wrong, and I believe you demonstrated that above...
In [29]: print(False and (False or True))
False
In [30]: print(False and False or True)
True
> If you use a backslashes at the end of line, emacs will double-indent
> the following lines, but I think you said you prefer paretheses...
Yes, I much prefer the parentheses -- partly because PEP-8 suggests it
but mostly because the escapes get lost too easily.
HH
More information about the Python-list
mailing list