For review: PEP 308 - If-then-else expression

Harvey Thomas hst at empolis.co.uk
Fri Feb 7 20:05:01 CET 2003


Jack Diederich wrote:

> Sent: 07 February 2003 18:18
> To: python-list at python.org
> Subject: Re: For review: PEP 308 - If-then-else expression
> 
> 
> On Fri, Feb 07, 2003 at 06:46:55PM +0100, holger krekel wrote:
> > What about a missing else clause? e.g. 
> > 
> >         <expression> if <condition>
> 
> if (<condition>): <expression>
> 
> is already legal so I'm -1 for yet another way to do it
> 
> > Allowing it could be nice for stuff like 
> >     result = obj(...) if callable(obj)
> 
> -1 as above
> 
> > Note though, that this proposal obfuscates control "flow"  
> > (which guido already knows, of course).  You can't read it 
> > neither from "left to right" nor from "right to left".  
> 
> a good reason for -1, another would be that perl has both
> ways of doing it ;)
> 
Agree with your comments.

What about a built-in function?

iff(<condition>, <trueresult>, falseresult) which returns <trueresult> if <condition> is true,
otherwise returns <falseresult

The flow is left to right (more or less), it's similar to constructs in other languages.

It can of course be written in Python currently in a rather horrible way.

Harvey

_____________________________________________________________________
This message has been checked for all known viruses by the MessageLabs Virus Scanning Service.





More information about the Python-list mailing list