Proposed new conditional operator: "or else"
Roy Smith
roy at panix.com
Tue Dec 2 20:49:04 EST 2014
In article <mailman.16498.1417544472.18130.python-list at python.org>,
Chris Angelico <rosuav at gmail.com> wrote:
> On Wed, Dec 3, 2014 at 4:41 AM, Zachary Ware
> <zachary.ware+pylist at gmail.com> wrote:
> > On Tue, Dec 2, 2014 at 11:18 AM, Roy Smith <roy at panix.com> wrote:
> >> Wouldnât it be neat to write:
> >>
> >> foo == 42 or else
> >>
> >> and have that be an synonym for:
> >>
> >> assert foo == 42
> >>
> >> :-)
> >
> > Never going to happen, but I like it! Perhaps raise IntimidationError
> > instead of AssertionError when it fails?
>
> Definitely. That's what I first thought, when I saw the subject line.
>
> Additionally, whenever this construct is used, the "yield" statement
> (expression, whatever) will be redefined to yield to intimidation and
> make the statement true, whatever it takes. In the above example,
> "yield" would decide which out of foo and 42 is more amenable to
> change, and altering it to be equal to the other. (It may also find
> that == is the most amenable, and alter its definition such that foo
> and 42 become equal.)
>
> ChrisA
This could be handy in the field of forensic accounting.
More information about the Python-list
mailing list