[Python-ideas] except expression

M.-A. Lemburg mal at egenix.com
Thu Feb 13 11:10:40 CET 2014


On 13.02.2014 10:24, Nick Coghlan wrote:
> General comment: like Raymond, I'm inclined to favour a nice expression
> friendly exception handling syntax, precisely because of the proliferation
> of relatively ad hoc alternative solutions (in particular, the popularity
> of being able to pass in default values to handle empty iterables).

Here's a variant the resembles the code you'd write in a helper
function to achieve the same thing, only stripped down somewhat:

x = something() except ValueError return default_value

def try_something():
    try:
        return something()
    except ValueError:
        return default_value

x = something() except ValueError as exc return exc.message

def try_something():
    try:
        return something()
    except ValueError as exc
        return exc.message

Obviously, having a keyword "use" would make a better fit :-)

x = something() except ValueError use default_value

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 13 2014)
>>> Python Projects, Consulting and Support ...   http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ...       http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2014-02-12: Released mxODBC.Connect 2.0.4 ...     http://egenix.com/go53

::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the Python-ideas mailing list