Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65406

Re: Postfix conditionals

References <mailman.4966.1388953508.18130.python-list@python.org> <8SVHu.12417$MB1.2814@fx09.am4> <87lhxro3u0.fsf@gkayaalp.com>
Date 2014-02-04 16:23 +1100
Subject Re: Postfix conditionals
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.6379.1391491416.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Feb 4, 2014 at 4:16 PM, Göktuğ Kayaalp <self@gkayaalp.com> wrote:
> With my proposal implemented, the language would
> would be encouraging having multiple statements in one line, that looks
> like a single statement, but is indeed a composition of two.

I wouldn't have a problem with

if not i: break

in Python, as long as the condition is short. In something that reads
from a socket until the other end closes, for instance, I'm fine with
this:

while True:
    data = sock.read(1024)
    if not data: break
    do_stuff_with(data)

which will stop as soon as sock.read() returns "", which it does when
the other end is gone. (I wrote something doing exactly this today,
and did exactly this. Probably could have made the code a bit simpler
if I could depend on Python 3.3, but it has to run on 2.7 and maybe
2.6 so I had to stick with their facilities.)

Yes, it's two statements, but a list comprehension is a whole pile of
statement-y things, and that's usually a single line. If it's doing
one conceptual action, it's okay to not split it.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-01-05 22:24 +0200
  Re: Postfix conditionals Roy Smith <roy@panix.com> - 2014-01-05 15:41 -0500
    Re: Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-01-05 22:54 +0200
    Re: Postfix conditionals Dan Stromberg <drsalists@gmail.com> - 2014-01-05 13:08 -0800
  Re: Postfix conditionals "Rhodri James" <rhodri@wildebst.org.uk> - 2014-01-06 01:40 +0000
    Re: Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-01-06 09:51 +0200
      Re: Postfix conditionals "Rhodri James" <rhodri@wildebst.org.uk> - 2014-01-07 00:48 +0000
  Re: Postfix conditionals "BartC" <bc@freeuk.com> - 2014-02-03 23:43 +0000
    Re: Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-02-04 07:16 +0200
      Re: Postfix conditionals "BartC" <bc@freeuk.com> - 2014-02-04 10:00 +0000
    Re: Postfix conditionals Chris Angelico <rosuav@gmail.com> - 2014-02-04 16:23 +1100

csiph-web