Proposed new conditional operator: "or else"

Sturla Molden sturla.molden at gmail.com
Tue Dec 2 19:54:26 EST 2014


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?

I guess the "or else" statement should do this:

   <condition> or else <threat>

where the statement <threat> is executed if the statement <condition>
evaluates to false.

In absence of an explicit threat

  <condition> or else

it should raise IntimidationError if <condition> evaluates to false false.

If <condition> evaluates to true it should just return <conditon>.



Sturla




More information about the Python-list mailing list