Python Newbie
Joshua Landau
joshua.landau.ws at gmail.com
Sun Feb 24 21:59:48 EST 2013
On 25 February 2013 02:08, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Sun, 24 Feb 2013 21:58:36 +0000, Joshua Landau
> <joshua.landau.ws at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130225/1375792d/attachment.html>
More information about the Python-list
mailing list