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


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

Re: Proposed new conditional operator: "or else"

Started byMichael Torrie <torriem@gmail.com>
First post2014-12-02 18:51 -0700
Last post2014-12-02 18:51 -0700
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#81823 — Re: Proposed new conditional operator: "or else"

FromMichael Torrie <torriem@gmail.com>
Date2014-12-02 18:51 -0700
SubjectRe: Proposed new conditional operator: "or else"
Message-ID<mailman.16506.1417571510.18130.python-list@python.org>
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?"

[toc] | [standalone]


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


csiph-web