Path: csiph.com!usenet.pasdenom.info!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'that?': 0.05; 'subject:Python': 0.06; 'input,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '-tkc': 0.16; 'input:': 0.16; 'received:80.91.229.3': 0.16; 'received:dyn.optonline.net': 0.16; 'received:optonline.net': 0.16; 'received:plane.gmane.org': 0.16; 'so!': 0.16; 'subject:breaking': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'fit': 0.20; '>>>': 0.22; 'input': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'tim': 0.29; "doesn't": 0.30; 'chase': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'handled': 0.32; 'really': 0.36; "didn't": 0.36; 'subject:?': 0.36; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; '2nd': 0.60; 'statement,': 0.68; 'fails,': 0.84; 'subject:long': 0.84; 'suspicion': 0.84; 'sorry.': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: Python and PEP8 - Recommendations on breaking up long lines? Date: Thu, 28 Nov 2013 12:26:11 -0500 References: <5296bf7d$0$29995$c3e8da3$5496439d@news.astraweb.com> <20131128080413.10d4c808@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: ool-4356373c.dyn.optonline.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: <20131128080413.10d4c808@bigbox.christie.dr> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385659809 news.xs4all.nl 15869 [2001:888:2000:d::a6]:47299 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60716 On 11/28/13 9:04 AM, Tim Chase wrote: > On 2013-11-28 03:58, Steven D'Aprano wrote: >>> input = open(self.full_path) >>> output = open(self.output_csv, 'ab') >>> with input as input, output as output: >>> ... >> >> That's really clever! Why didn't I think of that? > > Because if the 2nd output fails, the input doesn't get closed as > it {w,sh}ould in a with-statement? :-) D'oh, sorry. A doubly-nested with statement? input = open(self.full_path) with input: output = open(self.output_csv, 'ab') with output: ... Of course, if you were willing to use a doubly-nested with statement, then the original open-in-the-with form would have fit in 80 chars... Also, I have a sneaking suspicion there's still an error case not handled well, someone will point it out if so! --Ned. > > -tkc