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; 'warnings': 0.04; 'explicitly': 0.05; 'output': 0.05; 'sufficient': 0.05; 'subject:Python': 0.06; '"""': 0.07; '"as': 0.07; 'context': 0.07; 'fixes': 0.07; 'lines,': 0.07; 'string': 0.09; 'input,': 0.09; 'permissions': 0.09; 'quotes:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'statements': 0.09; 'python': 0.11; 'jan': 0.12; 'anyway': 0.14; 'mostly': 0.14; 'comments:': 0.16; 'docstrings': 0.16; 'exist."""': 0.16; 'guessing': 0.16; 'newlines': 0.16; 'parentheses': 0.16; 'pep8': 0.16; 'pythonic': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'recognised': 0.16; 'reedy': 0.16; 'subject:breaking': 0.16; 'syntax,': 0.16; 'thoughts?': 0.16; 'url.': 0.16; 'wraps': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'module': 0.19; 'trying': 0.19; "python's": 0.19; 'split': 0.19; 'meant': 0.20; 'fit': 0.20; 'work,': 0.20; 'code,': 0.22; 'input': 0.22; 'example': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'convenient': 0.24; 'documented': 0.24; 'file.': 0.24; "i've": 0.25; 'possibly': 0.26; 'second': 0.26; 'least': 0.26; '(for': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'feature': 0.29; 'wonder': 0.29; 'especially': 0.30; "i'm": 0.30; 'getting': 0.31; 'lines': 0.31; 'page.': 0.31; 'breaking': 0.31; 'comments,': 0.31; 'ok.': 0.31; 'quotes': 0.31; 'though.': 0.31; 'way?': 0.31; 'file': 0.32; 'another': 0.32; 'open': 0.33; 'says': 0.33; 'running': 0.33; 'third': 0.33; 'comment': 0.34; 'noticed': 0.34; 'could': 0.34; "can't": 0.35; 'problem.': 0.35; 'skip:s 30': 0.35; 'case,': 0.35; 'there': 0.35; 'marks': 0.36; 'ones,': 0.36; 'right?': 0.36; 'subject:?': 0.36; 'example,': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'how': 0.40; 'easy': 0.60; 'blank': 0.60; 'free': 0.61; 'received:173': 0.61; 'further': 0.61; 'first': 0.61; 'such': 0.63; 'become': 0.64; 'between': 0.67; 'believe': 0.68; 'ending': 0.78; 'introduce': 0.78; 'potentially': 0.81; 'disappear': 0.84; 'received:fios.verizon.net': 0.84; 'subject:long': 0.84; 'victor': 0.84; 'warning.': 0.84; 'messages:': 0.91; 'urls,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Python and PEP8 - Recommendations on breaking up long lines? Date: Wed, 27 Nov 2013 21:55:08 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: 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: 118 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385607330 news.xs4all.nl 15959 [2001:888:2000:d::a6]:48848 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60664 On 11/27/2013 8:57 PM, Victor Hooi wrote: [sorry if the re-wrapping mis-formats anything] > I'm running pep8 Ah yes, the module that turns PEP8 into the straightjacket it explicitly says it is not meant to be. > across my code, We mostly to not change existing stdlib modules to conform unless they are being edited anyway for fixes and features. > and getting warnings about my long lines (> 80 characters). You are free to ignore such > I'm wonder what's the recommended way to handle the below cases, and > fit under 80 characters. > > First example - multiple context handlers: > > with open(self.full_path, 'r') as input, open(self.output_csv, 'ab') > as output: > > and in my case, with indents, the 80-character marks is just before > the ending "as output". > > What's the standard recognised way to split this across multiple > lines, so that I'm under 80 characters? I believe () does not work, so put \ after 'input,'. > I can't just split after the "as input," as that isn't valid syntax, > and there's no convenient parentheses for me to split over. > > Is there a standard Pythonic way? > > Second example - long error messages: > > self.logger.error('Unable to open input or output file - %s. Please > check you have sufficient permissions and the file and parent > directory exist.' % e) > > I can use triple quotes: > > self.logger.error( """Unable to open input or output file - %s. > Please check you have sufficient permissions and the file and parent > directory exist.""" % e) > > However, that will introduce newlines in the message, which I don't > want. > > I can use backslashes: > > self.logger.error( 'Unable to open input or output file - %s. Please > check you\ have sufficient permissions and the file and parent > directory\ exist.' % e) > > which won't introduce newlines. > > Or I can put them all as separate strings, and trust Python to glue > them together: Such gluing in a documented feature and I think you can trust it to not disappear (for at least a decade ;-). > self.logger.error( 'Unable to open input or output file - %s. Please > check you' 'have sufficient permissions and the file and parent > directory' 'exist.' % e) > > Which way is the recommended Pythonic way? > > Third example - long comments: > > """ NB - We can't use Psycopg2's parametised statements here, as that > automatically wraps everything in single quotes. So > s3://my_bucket/my_file.csv.gz would become > s3://'my_bucket'/'my_file.csv.gz'. Hence, we use Python's normal > string formating - this could potentially exposes us to SQL injection > attacks via the config.yaml file. I'm not aware of any easy ways > around this currently though - I'm open to suggestions though. See > http://stackoverflow.com/questions/9354392/psycopg2-cursor-execute-with-sql-query-parameter-causes-syntax-error > >for further information. """ > > In this case, I'm guessing a using triple quotes (""") is a better > idea with multi-line comments, right? Either are ok. > However, I've noticed that I can't seem to put in line-breaks inside > the comment without triggering a warning. For example, trying to put > in another empty line in between lines 6 and 7 above causes a > warning. Blank lines are normal in triple-quoted strings and recommended for docstrings longer than a line. So I am puzzled as to your problem. > Also, how would I split up the long URLs? Don't if you can possibly avoid it. > Breaking it up makes it annoying to use the URL. Yep. > Thoughts? Some urls, especially long ones, have extra tracking/query junk that can be removed while still pointing to the page. -- Terry Jan Reedy