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


Groups > comp.lang.python > #81823

Re: Proposed new conditional operator: "or else"

Date 2014-12-02 18:51 -0700
From Michael Torrie <torriem@gmail.com>
Subject Re: Proposed new conditional operator: "or else"
References <C2BEED98-4CCA-4EDE-8FDF-F235B478055C@panix.com>
Newsgroups comp.lang.python
Message-ID <mailman.16506.1417571510.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/02/2014 10:18 AM, Roy Smith wrote:
> 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']

But isn't that syntactically equivalent of this?

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

Seems to be what you're looking for with "or else" unless I
misunderstand what you're proposing.

Doing a bit of testing in the interpreter and I find that a combination
of Python's truthiness semantics and short-circuit evaluation seems to
give a consistent result. Consider:

'a word' or False => 'a word'
'a word' or True => 'a word'
False or 'a word' => 'a word'
True or 'a word' => True

Is this similar to what you'd expect with "or else?"

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


Thread

Re: Proposed new conditional operator: "or else" Michael Torrie <torriem@gmail.com> - 2014-12-02 18:51 -0700

csiph-web