[Python-Dev] (try-except) conditional expression similar to (if-else) conditional (PEP 308)

Xavier Morel catch-all at masklinn.net
Sat Aug 8 10:17:10 CEST 2009


On 8 Aug 2009, at 08:02 , Steven D'Aprano wrote:
> On Fri, 7 Aug 2009 08:22:14 pm Kristján Valur Jónsson wrote:
>> Unless I am very much mistaken, this is the approach Ruby takes.
>> Everything is an expression.  For example, the value of a block is
>> the value of The last expression in the block.
>
> Copying what other languages do is not necessarily a bad thing, but  
> that
> would fail both "explicit is better than implicit" and "in the face of
> ambiguity, avoid the temptation to guess".
The first objection one might be able to give, you maybe, but the  
second one? Where's the ambiguity in "compound statements return the  
result of the last evaluated expression"?

> It's not immediately obvious to me why the last expression should be
> given that privileged rule. Why not the first expression?
>
Because it wouldn't make any sense? When you're computing something,  
the value you want is the one at the end of the computation (usually  
called a result), not some random one somewhere else.



More information about the Python-Dev mailing list