I have wanted this sort of syntax before but assumed it wasn't feasible and
never considered how I'd want it to look. One possibility that wasn't
mentioned in Chris's earlier PEP is this:

`value = func() except Exception with default`

Though you'd almost certainly want to use a more specific exception.


On Thu, Aug 6, 2020, 4:35 PM Chris Angelico <[email protected]> wrote:

> On Fri, Aug 7, 2020 at 6:28 AM <[email protected]> wrote:
> >
> > > Have a look at PEP 463, which looks into this in some detail.
> >
> > I wish this PEP had gained more traction.  Sooner or later, everyone
> wants an expression form of a try/except.
> >
> > When it comes to expressing "in the event of this exception, I want this
> default",  exception expressions read much more nicely than an equivalent
> try/except block.
> >
> > Also, new syntax would keep the rest of the language clean so that don't
> end up adding dozens of get() methods. Or r having us expand function
> signatures with default arguments, like min() and max() functions for
> example.
> >
> > It would be great if this PEP were to be resurrected.
> >
>
> I'd be happy to work on it again if anyone else has suggestions for
> better justifications - see the rejection notice at the top of the
> PEP.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/TN6MWJ3Y7VYHGPJUS7FKRDNXEYST2W5D/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/XH6A3A2K4LHC6IUFEKP5I74CFBSYO5QE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to