[Python-ideas] One-line "try with" statement

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Mar 3 22:36:52 CET 2013


Stefan Behnel wrote:
> The above example therefore strikes me as
> useless. If you need a try-except around a with block, then your context
> manager is doing something wrong.

A with statement is equivalent to try-finally, not try-except,
so if you want to catch the exception you still need to put
a try-except somewhere.

However, I can't see why you're any more likely to want to
put try-except directly around a with statement than any
other kind of statement. So why ask for try-with in
particular, and not try-if, try-while, try-for, ...?

-- 
Greg



More information about the Python-ideas mailing list