Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104542

Re: context managers inline?

From Neal Becker <ndbecker2@gmail.com>
Newsgroups comp.lang.python
Subject Re: context managers inline?
Date 2016-03-10 13:59 -0500
Message-ID <mailman.146.1457636383.15725.python-list@python.org> (permalink)
References <mailman.144.1457634813.15725.python-list@python.org> <5474fede-5093-4a0b-8e1e-22737e6e7810@googlegroups.com>

Show all headers | View raw


sohcahtoa82@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?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

context managers inline? Neal Becker <ndbecker2@gmail.com> - 2016-03-10 13:33 -0500
  Re: context managers inline? sohcahtoa82@gmail.com - 2016-03-10 10:47 -0800
    Re: context managers inline? Neal Becker <ndbecker2@gmail.com> - 2016-03-10 13:59 -0500
    Re: context managers inline? Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-10 12:19 -0700
    Re: context managers inline? jmp <jeanmichel@sequans.com> - 2016-03-11 11:42 +0100
  Re: context managers inline? Steven D'Aprano <steve@pearwood.info> - 2016-03-11 15:35 +1100

csiph-web