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


Groups > comp.lang.python > #104607

Re: context managers inline?

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.freenet.ag!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail
From jmp <jeanmichel@sequans.com>
Newsgroups comp.lang.python
Subject Re: context managers inline?
Date Fri, 11 Mar 2016 11:42:58 +0100
Lines 23
Message-ID <mailman.13.1457693002.26429.python-list@python.org> (permalink)
References <mailman.144.1457634813.15725.python-list@python.org> <5474fede-5093-4a0b-8e1e-22737e6e7810@googlegroups.com> <nbsg6k$c3o$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de 2DIz1gggqFyeBlDBW4ZosQfboP+Knr7brZYmOU+jYgrA==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'cleanup': 0.07; "'rb')": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'thursday,': 0.13; '2016': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:inline': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'load': 0.20; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'print': 0.30; 'file': 0.34; 'gets': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'received:194': 0.61; 'email addr:gmail.com': 0.62; 'charset:windows-1252': 0.62; 'march': 0.64; 'as:': 0.79; '(open': 0.84; 'becker': 0.84; 'construct': 0.84
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host paris.sequans.com
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
In-Reply-To <nbsg6k$c3o$1@ger.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:104607

Show key headers only | View raw


On 03/10/2016 07:59 PM, Neal Becker wrote:
> 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?
>

You you really want a 1 liner

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


jm

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