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


Groups > comp.lang.python > #81804 > unrolled thread

Proposed new conditional operator: "or else"

Started byRoy Smith <roy@panix.com>
First post2014-12-02 12:18 -0500
Last post2014-12-02 12:18 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#81804 — Proposed new conditional operator: "or else"

FromRoy Smith <roy@panix.com>
Date2014-12-02 12:18 -0500
SubjectProposed new conditional operator: "or else"
Message-ID<mailman.16495.1417541801.18130.python-list@python.org>

[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

:-)

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web