[Python-ideas] Potential PEP: with/except

Michael Selik mike at selik.org
Tue Jan 22 15:31:42 EST 2019

On Tue, Jan 22, 2019, 12:11 PM Paul Ferrell <pflarr at gmail.com wrote:

> I see this as the natural evolution of what 'with' is all about -
> replacing necessary try-finally blocks with something more elegant. We just
> didn't include the 'except' portion.

The time machine strikes again. In fact, you can handle exceptions with a
context manager object. Whatever you're with-ing must have a dunder exit
method, which received any exceptions raised in the block as an argument.
Return true and the exception is suppressed.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190122/7850d035/attachment-0001.html>

More information about the Python-ideas mailing list