[Python-ideas] "try with" syntactic sugar

Eric Smith eric at trueblade.com
Thu Feb 26 16:10:40 CET 2009


Daniel Stutzbach wrote:
...
> The "with" statement is great, but it results in the bulk of the code 
> being indented twice.  I'd like to propose a little syntactic sugar, the 
> "try with":
> 
> try with something as f:
>     many lines of code
> except some_error:
>     handle error

Not commenting on how useful the proposal is (I'm mostly stuck in Python 
2.4), but couldn't this be:

with something as f:
     many lines of code
except some_error:
     handle error

That is, you don't really need the "try", since the above syntax is 
currently illegal?

Eric.




More information about the Python-ideas mailing list