On 25 February 2013 02:08, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote:
> On Sun, 24 Feb 2013 21:58:36 +0000, Joshua Landau > <joshua.landau...@gmail.com> declaimed the following in > gmane.comp.python.general: > > > > > > condition1 = long_condition_expression_1 > > condition2 = long_condition_expression_2 > > condition3 = long_condition_expression_3 > > > > if condition1 and condition2 and condition3: > > STUFF > > > > No multiline needed. If you have *many* conditions, then: > > > Except that Python does short-circuit evaluation; your scheme will > fail in some situations: > > >>> x = 0 > >>> if x != 0 and 32 / x > 4: > ... print "we passed" > ... > >>> c1 = x != 0 > >>> c2 = 32 / x > 4 > Traceback (most recent call last): > File "<interactive input>", line 1, in <module> > ZeroDivisionError: integer division or modulo by zero > >>> > Yeah, well... context*. There are perfectly legitimate ways of doing that too. A simple one would be: > supercondition = ( > long_condition_expression_1 and > long_condition_expression_2 and > long_condition_expression_3 > ) > > if supercondition: ... Please note the problem of the original is that the indentation dedents and indents in too quick a sequence: > if ( > something_here): # Where do I indent this to? > something_else There are standards, but I don't like the style. I thought it worth mentioning as we were all being subjective anyway ;P. It's much worse than: > if something_here: something_else #on the same line which is already explicitly advised against. * By which I mean: fair point
-- http://mail.python.org/mailman/listinfo/python-list