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


Groups > comp.lang.python > #81804

Proposed new conditional operator: "or else"

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <roy@panix.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'syntax': 0.04; 'python': 0.11; 'construct.': 0.16; 'received:166.84': 0.16; 'received:166.84.1': 0.16; 'received:166.84.1.75': 0.16; 'received:166.84.1.89': 0.16; 'received:corp.google.com': 0.16; 'received:l2mail1.panix.com': 0.16; 'received:mailbackend.panix.com': 0.16; 'received:panix.com': 0.16; 'refactoring': 0.16; 'statement.': 0.16; 'which,': 0.16; 'wouldn\x92t': 0.16; 'essential': 0.16; ':-)': 0.16; 'bit': 0.19; 'received:166': 0.19; 'code,': 0.22; 'error': 0.23; 'assert': 0.31; 'received:72.14': 0.33; 'could': 0.34; 'created': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:new': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'subject:"': 0.60; 'new': 0.61; 'today,': 0.61; 'header:Message- Id:1': 0.63; 'for:': 0.64; 'charset:windows-1252': 0.65; 'subject:else': 0.84; 'write:': 0.91
From Roy Smith <roy@panix.com>
Content-Type multipart/alternative; boundary="Apple-Mail=_3583CAE6-DD3D-47D1-B5B2-7E9E53B634DE"
Subject Proposed new conditional operator: "or else"
Date Tue, 2 Dec 2014 12:18:36 -0500
To Python <python-list@python.org>
Mime-Version 1.0 (Mac OS X Mail 7.3 \(1878.6\))
X-Mailer Apple Mail (2.1878.6)
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.16495.1417541801.18130.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417541801 news.xs4all.nl 2959 [2001:888:2000:d::a6]:43523
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81804

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

In the process of refactoring some code, I serendipitously created what I think is an essential new bit of Python syntax.  The “or else” statement.  I ended up with:

        sites_string = args.sites or else self.config['sites']

which, of course, is a syntax error today, but it got me thinking what we could do with an “or else” construct.  Perhaps an alternative to assertions?  Wouldn’t it be neat to write:

   foo == 42 or else

and have that be an synonym for:

    assert foo == 42

:-)

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


Thread

Proposed new conditional operator: "or else" Roy Smith <roy@panix.com> - 2014-12-02 12:18 -0500

csiph-web