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


Groups > comp.lang.python > #81804

Proposed new conditional operator: "or else"

From Roy Smith <roy@panix.com>
Subject Proposed new conditional operator: "or else"
Date 2014-12-02 12:18 -0500
Newsgroups comp.lang.python
Message-ID <mailman.16495.1417541801.18130.python-list@python.org> (permalink)

Show all headers | 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