context managers inline?

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Mar 10 14:45:38 EST 2016


On 10/03/2016 18:33, Neal Becker wrote:
> Is there a way to ensure resource cleanup with a construct such as:
>
> x = load (open ('my file', 'rb))
>
> Is there a way to ensure this file gets closed?
>

I don't see how there can be.  Surely you must split it into two lines 
to use the context manager via the 'with' keyword, or you leave the one 
line as is and forego the context manager.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list