Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'broken': 0.04; 'skip:[ 20': 0.04; 'subject:Python': 0.06; 'amounts': 0.07; 'continuation': 0.07; 'lines,': 0.07; 'purpose.': 0.07; 'computed': 0.09; 'file)': 0.09; 'filename': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'repeated': 0.09; 'suggest': 0.14; '"insert': 0.16; 'bind': 0.16; 'block.': 0.16; 'columns': 0.16; 'expression,': 0.16; 'finney': 0.16; 'parentheses': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:breaking': 0.16; 'dependent': 0.19; 'header:User-Agent:1': 0.23; "i've": 0.25; 'least': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'ideal': 0.29; "doesn't": 0.30; 'statement': 0.30; 'convenience': 0.31; 'indentation': 0.31; 'writes:': 0.31; 'another': 0.32; 'cases': 0.33; 'but': 0.35; 'add': 0.35; 'subject:?': 0.36; 'easily': 0.37; 'ben': 0.38; 'to:addr:python-list': 0.38; 'previous': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'even': 0.60; 'easy': 0.60; 'expression': 0.60; 'break': 0.61; "you're": 0.61; 'further': 0.61; 'name': 0.63; 'skip:\xe2 10': 0.65; 'within': 0.65; '8bit%:40': 0.68; 'distinguish': 0.84; 'one;': 0.84; 'subject:long': 0.84; 'victor': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Python and PEP8 - Recommendations on breaking up long lines? Date: Thu, 28 Nov 2013 13:55:10 +1100 References: <34479463-b8a8-4417-9989-cd29369461c2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: rasputin.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-gpg.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:aiyEMDQUWPT2fcOlNCOdHvOhhTc= 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385607323 news.xs4all.nl 15954 [2001:888:2000:d::a6]:48700 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60663 Victor Hooi writes: > cur.executemany("INSERT INTO foobar_foobar_files VALUES (?)", > [[os.path.relpath(filename, foobar_input_folder)] for filename in filenames]) > > I've already broken it up using the parentheses But now the continuation line indentation is needlessly dependent on the content of the previous line. Better to just use a standard additional indentation (I prefer 8 columns to easily distinguish from block indentation) for any continuation line:: cur.executemany( "INSERT INTO foobar_foobar_files VALUES (?)", [ [os.path.relpath(filename, foobar_input_folder)] for filename in filenames]) Notice that further continuation within an existing continuation doesn't get another 8, but only another 4 columns. The whole statement is already distinguished, I don't need to add huge amounts of further indentation for that purpose. > if os.path.join(root, file) not in previously_processed_files and os.path.join(root, file)[:-3] not in previously_processed_files: In cases where the line is long because of a long expression, enclosing that expression in parens for clarification will then give you an easy way to break for continuation lines:: if ( os.path.join(root, file) not in previously_processed_files and os.path.join(root, file)[:-3] not in previously_processed_files): But that's still some long lines, and your repeated use of a computed value is an ideal opportunity to bind it to a convenience name for local use:: file_path = os.path.join(root, file) if ( file_path not in previously_processed_files and file_path[:-3] not in previously_processed_files): Not least because you're very likely going to use the value of ‘file_path’ yet again in the body of that ‘if’ block. -- \ “Two paradoxes are better than one; they may even suggest a | `\ solution.” —Edward Teller | _o__) | Ben Finney