Proposed new conditional operator: "or else"

Roy Smith roy at panix.com
Tue Dec 2 12:18:36 EST 2014


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

:-)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141202/df90ef7f/attachment.html>


More information about the Python-list mailing list