[Python-ideas] "try with" syntactic sugar
Daniel Stutzbach
daniel at stutzbachenterprises.com
Fri Feb 27 03:00:59 CET 2009
On Thu, Feb 26, 2009 at 7:28 PM, Bruce Frederiksen <dangyogi at gmail.com>wrote:
> How about this?
I tried it, but it matches quite a few comments and strings. Try putting a
"print repr(match.group(0))" in the innermost loop to debug it.
> On my last response, I mentioned a suggestion to add __throw__ to context
> managers. But then I remembered that the __exit__ method is already given
> the exception information if an exception is raised. So you can already do
> what I was suggesting now.
>
> I'm still curious as to how often you could share try/except cases by
> writing your own context managers.
>
Not particularly often. Much of the time, the exception handler has to
clean up the mess when a file is unexpectedly unreadable or SQL explodes,
and the clean-up bit is tied to the immediately surrounding code. YMMV.
--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090226/0641a34d/attachment.html>
More information about the Python-ideas
mailing list