[Python-ideas] "try with" syntactic sugar

Daniel Stutzbach daniel at stutzbachenterprises.com
Thu Feb 26 16:09:38 CET 2009

On Thu, Feb 26, 2009 at 8:44 AM, Calvin Spealman <ironfroggy at gmail.com>wrote:

> But... Do we also add try for:, try if:, try while:, etc.? Not
> terrible, but potentially terrible.

No, because they're rarely useful.  Modifying my script a little, less than
1% of my "if" and "for" statements are immediately preceded by "try",
compared to 68% of my "with" statements.

"with" blocks very frequently define the scope of an object that might
generate a particular type of exception (e.g., file object may throw
IOErrors, SQL transactions might through SQL exceptions, etc.).

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/6bf061cd/attachment.html>

More information about the Python-ideas mailing list