[Python-ideas] Automatic context managers

random832 at fastmail.us random832 at fastmail.us
Fri Apr 26 20:54:20 CEST 2013


On Fri, Apr 26, 2013, at 11:25, anatoly techtonik wrote:
> Ok. The proposal is patch Python to be able to write:
> 
>    boolean = open(resource).use()
> 
> Instead of:
> 
>    boolean = None
>    with open(resource) as tempvar:
>        boolean = tempvar.use()

What about a with expression?

boolean = x.use() with x as open(resource)



More information about the Python-ideas mailing list