Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Neal Becker Newsgroups: comp.lang.python Subject: Re: context managers inline? Date: Thu, 10 Mar 2016 13:59:31 -0500 Lines: 14 Message-ID: References: <5474fede-5093-4a0b-8e1e-22737e6e7810@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de +jviMDYJZJlpLnTN6N6UyAjlj3qIRwV4ymxRV2bECxMw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 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; 'load': 0.20; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'file': 0.34; 'gets': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'email addr:gmail.com': 0.62; 'march': 0.64; 'as:': 0.79; '(open': 0.84; 'becker': 0.84; 'construct': 0.84; 'received:139': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: exa2-in-fw-01-epn.hns.com User-Agent: KNode/4.14.10 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104542 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?