context managers inline?

sohcahtoa82 at gmail.com sohcahtoa82 at gmail.com
Thu Mar 10 13:47:05 EST 2016


On Thursday, March 10, 2016 at 10:33:47 AM UTC-8, 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?

with open('my file', 'rb') as f:
    x = load(f)




More information about the Python-list mailing list