Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.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.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'python.': 0.02; 'msg': 0.09; 'skip:% 20': 0.09; 'subject:question': 0.10; 'python': 0.11; 'wrote': 0.14; 'code?': 0.16; 'splitting': 0.16; 'terribly': 0.16; 'wrote:': 0.18; 'rules': 0.22; 'header:User-Agent:1': 0.23; 'question': 0.24; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'skip:( 20': 0.30; 'code': 0.31; 'lines': 0.31; 'breaking': 0.31; 'gary': 0.31; 'screen': 0.34; "i'd": 0.34; 'skip:s 30': 0.35; 'there': 0.35; 'really': 0.36; 'hi,': 0.36; 'received:10': 0.37; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'institute': 0.72; 'received:10.10': 0.74; 'received:204': 0.75; 'dr.': 0.77; 'eyes': 0.78; 'clearer': 0.84; 'ok?': 0.84 Date: Fri, 21 Jun 2013 15:26:07 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: n00b question on spacing References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371853574 news.xs4all.nl 15909 [2001:888:2000:d::a6]:47731 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48887 On 06/21/2013 02:17 PM, Yves S. Garret wrote: > Hi, I have a question about breaking up really long lines of code in > Python. > > I have the following line of code: > log.msg("Item wrote to MongoDB database %s/%s" > %(settings['MONGODB_DB'], settings['MONGODB_COLLECTION']), > level=log.DEBUG, spider=spider) > > Given the fact that it goes off very far to the right on my screen is > not terribly > pleasing to my eyes (and can be rude for other developers). > > I was thinking of splitting it up like so: > log.msg("Item wrote to MongoDB database %s/%s" > %(settings['MONGODB_DB'], settings['MONGODB_COLLECTION']), > level=log.DEBUG, spider=spider) > > Is this ok? Are there any rules in Python when it comes to breaking > up long lines of > code? > > This is how I'd do it: (And it's *FAR* clearer -- You win no points for clarity by having it all in one statement.) fmt = "Item wrote to MongoDB database %s/%s" msg = fmt % (settings['MONGODB_DB'], settings['MONGODB_COLLECTION']) log.msg(msg, level=log.DEBUG, spider=spider) Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418