[Python-ideas] "try with" syntactic sugar

Daniel Stutzbach daniel at stutzbachenterprises.com
Sun Mar 1 21:49:06 CET 2009

On Fri, Feb 27, 2009 at 1:20 PM, Guido van Rossum <guido at python.org> wrote:

> On Fri, Feb 27, 2009 at 4:49 AM, Curt Hagenlocher <curt at hagenlocher.org>
> wrote:
> > That way lies madness.  What distinguishes "with" from other compound
> > statements is that it's already about resource management in the face
> > of possible exceptions.
> Still, a firm -1 from me. Once we have "try try" I'm sure people are
> going to clamor for "try if", "try while", "try for", even (oh horror
> :-) "try try". I don't think we should complicate the syntax just to
> save one level of indentation occasionally.

In addition to reasons outlined by Curt, "with" is unique because it's
short-hand for a "try" block with a "finally" clause.  Unfortunately, "with"
doesn't allow for other clauses and so I often end up using both "try" and

Also, "try if", "try while", and "try for" wouldn't work because they
already have a meaning for the "else" clause.  "with" does not.

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/20090301/16ae5979/attachment.html>

More information about the Python-ideas mailing list