PEP 308: I liked the original proposal better

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Sun Feb 23 23:04:00 EST 2003


> From: Greg Ewing (using news.cis.dfn.de) [mailto:me at privacy.net]
> 
> As far as I can see, no one proposal appears to have
> anywhere near a majority supporting it, and the minority
> which supports x if C else y doesn't seem to be
> significantly smaller than the minority supporting
> any other single proposal.
> 
> I just feel that it has been dismissed too soon.

Nah - they've all been dismissed too late.

The One True Pythonic Ternary Operator is

class bool:

    def ifelse (self, trueresult, falseresult, callable=False):
        if self:
            if callable:
                return trueresult()
            else:
                return trueresult
        else:
            if callable:
                return falseresult()
            else:
                return falseresult

Short-circuiting and everything else required in one.

this-was-going-to-be-a-wink-but-I-like-this-idea-ly yours

Tim Delaney





More information about the Python-list mailing list