On 03/10/2016 07:59 PM, Neal Becker wrote:
sohcahto...@gmail.com wrote:

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)

But not in a 1-line, composable manner?


You you really want a 1 liner

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


jm

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to