Code formatting question: conditional expression

John Posner jjposner at
Wed Aug 19 22:36:20 CEST 2009

Diez wrote:
> No. I love them. But not if they are so large that they stretch over several
> lines (or to many columns).
>  foo = bar if cond else baz
> is more than fine for me. But
>  foo = I_need_to_do_something_really_complicated_here() if cond else baz
> isn't, because one doesn't grasp as easily in one look that we're talking a
> ternary operator here.

But the right side of my brain (see Peter Keller's discussion in the 
recent "importance of syntax" thread) finds it quite easy to recognize 
this as a ternary op:
  foo = (I_need_to_do_something_really_complicated_here()
        if cond else

The whitespace below "foo" provides a visual hint, which is confirmed by 
the nearby appearance of "if" on the second line. De gustibus non est 
disputandum! (or not)

Many thanks to all responders!


More information about the Python-list mailing list