[Python-ideas] except expression

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Feb 13 22:18:01 CET 2014


Chris Angelico wrote:

> phone = addressbook[name] except KeyError or "Unknown"

How about

    phone = addressbook[name] except "Unknown" if KeyError

Yes, it puts things in a different order from the except
statement, but I don't think that's any worse than the
if-expression being ordered differently from the if-statement,
and it has the same benefit, i.e. reading more smoothly.

-- 
Greg


More information about the Python-ideas mailing list