Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!news.astraweb.com!border2.a.newsrouter.astraweb.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; '(at': 0.04; 'output': 0.05; 'subject:Python': 0.06; 'assign': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'input,': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; '2.7': 0.14; '(use': 0.16; 'clauses': 0.16; 'fine.': 0.16; 'received:69.93': 0.16; 'subject:breaking': 0.16; 'wrote:': 0.18; 'have:': 0.19; 'input': 0.22; 'header:User-Agent:1': 0.23; 'skip': 0.24; 'looks': 0.24; '(or': 0.24; 'least': 0.26; 'header:In-Reply- To:1': 0.27; 'important.': 0.30; 'statement': 0.30; 'open': 0.33; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'two': 0.37; 'skip:o 20': 0.38; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'expression': 0.60; 'received:173': 0.61; 'name': 0.63; 'different': 0.65; 'batchelder': 0.84; 'subject:long': 0.84 Date: Wed, 27 Nov 2013 19:15:15 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Python and PEP8 - Recommendations on breaking up long lines? References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator3304.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source-IP: 173.12.184.233 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([173.12.184.233]) [173.12.184.233]:54512 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3IzMzA0Lmhvc3RnYXRvci5jb20= 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385609859 news.xs4all.nl 15899 [2001:888:2000:d::a6]:47338 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60673 On 11/27/2013 06:59 PM, Ned Batchelder wrote: > > The important thing in a with statement is that the assigned name will be closed (or otherwise exited) automatically. > The open call is just the expression used to assign the name. The expression there isn't really important. This looks > odd, but works the same as what you have: > > input = open(self.full_path) > output = open(self.output_csv, 'ab') > with input as input, output as output: > ... > > (Use different names for the two parts of the "as" clauses if you like.) Or skip the `as` clauses all together: input = ... output = ... with input, output: ... works just fine. (At least on 2.7 where I tested it. ;) -- ~Ethan~