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


Groups > comp.lang.python > #63220

Postfix conditionals

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <self@gkayaalp.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'syntax': 0.04; 'python:': 0.09; 'similar,': 0.09; 'runs': 0.10; 'added.': 0.16; 'determines': 0.16; 'notation,': 0.16; 'readability': 0.16; 'received:72.5': 0.16; 'received:72.5.230': 0.16; 'received:sender1.zohomail.com': 0.16; 'received:zohomail.com': 0.16; 'ternary': 0.16; 'thoughts': 0.19; 'example': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'looks': 0.24; 'equivalent': 0.26; 'second': 0.26; 'compared': 0.30; 'statement': 0.30; 'code': 0.31; 'posting': 0.31; 'perl': 0.31; 'piece': 0.31; 'community': 0.33; 'knowledge': 0.35; 'there': 0.35; 'i.e.': 0.36; 'hi,': 0.36; 'two': 0.37; 'list.': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'break': 0.61; 'from:charset:utf-8': 0.61; 'first': 0.61; 'kind': 0.63; 'here': 0.66; 'believe': 0.68; 'statement,': 0.68; 'superior': 0.69; 'opinions': 0.70; 'lack': 0.78; 'not:': 0.91
Date Sun, 05 Jan 2014 22:24:53 +0200
From Göktuğ Kayaalp <self@gkayaalp.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.org
Subject Postfix conditionals
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-ZohoMailClient External
X-Zoho-Virus-Status 2
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4966.1388953508.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1388953508 news.xs4all.nl 2967 [2001:888:2000:d::a6]:35931
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63220

Show key headers only | View raw


Hi,

AFAIK, we do not have "postfix conditionals" in Python, i.e. a condition 
appended to a
statement, which determines whether the statement runs or not:

   py> for i in [False]:
   ...     break if not i

The above piece of code is equivalent to this in Python:

   py> for i in [False]:
   ...    if not i
   ...        break

I believe that the first example is superior to the second example when 
the two is compared
for readability and intuitiveness.  We already have a ternary statement 
that looks similar,

   py> print('hi') if True else None

so I reckon there would be no breakage in old code if this kind of 
syntax was added.  Ruby has
this, and AFAIK Perl also does.

I lack the knowledge of whether the community has opinions on this kind 
of notation, so I am
posting this here instead of the ideas list.  What are your thoughts on 
this?

         gk

Back to comp.lang.python | Previous | NextNext 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