Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'programmer': 0.03; 'output': 0.05; 'that?': 0.05; 'subject:Python': 0.06; 'exception.': 0.09; 'input,': 0.09; 'runtime': 0.09; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'subject:breaking': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'input': 0.22; 'import': 0.22; 'error': 0.23; 'header:In-Reply-To:1': 0.27; 'room': 0.29; "doesn't": 0.30; "d'aprano": 0.31; 'steven': 0.31; 'actual': 0.34; 'could': 0.34; 'but': 0.35; 'really': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; '2nd': 0.60; 'more': 0.64; 'fails,': 0.84; 'partial': 0.84; 'received:50.22': 0.84; 'subject:long': 0.84 Date: Thu, 28 Nov 2013 08:04:13 -0600 From: Tim Chase To: python-list@python.org Subject: Re: Python and PEP8 - Recommendations on breaking up long lines? In-Reply-To: <5296bf7d$0$29995$c3e8da3$5496439d@news.astraweb.com> References: <5296bf7d$0$29995$c3e8da3$5496439d@news.astraweb.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385647374 news.xs4all.nl 15898 [2001:888:2000:d::a6]:44017 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60688 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? :-) You could work around this with: from functools import partial in_ = partial(open, self.full_path) out_ = partial(open, self.output_csv, 'ab') with in_() as input, out_() as output: do_stuff() There's still room for programmer error if you don't have an "output_csv" property on self and you get an AttributeError, but that's more of a "dumb programmer error" rather than an actual runtime exception. -tkc