Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'lawrence': 0.09; 'msg': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:% 20': 0.09; 'subject:question': 0.10; 'wrote': 0.14; 'formatting,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'splitting': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'code:': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'skip:( 20': 0.30; 'along': 0.30; "i'm": 0.30; 'lines': 0.31; 'ball': 0.31; 'gary': 0.31; 'really,': 0.31; 'style': 0.33; "i'd": 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'skip:" 50': 0.36; 'next': 0.36; 'should': 0.36; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'black': 0.61; 'of:': 0.68; 'watching': 0.68; 'clearer': 0.84; 'white,': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: n00b question on spacing Date: Sat, 22 Jun 2013 15:40:26 +0100 References: <51C4D2FF.8000709@digipen.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-92-24-210-99.ppp.as43234.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: X-Antivirus: avast! (VPS 130622-0, 22/06/2013), Outbound message X-Antivirus-Status: Clean 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371912044 news.xs4all.nl 15864 [2001:888:2000:d::a6]:49867 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48924 On 22/06/2013 14:36, Joshua Landau wrote: > On 21 June 2013 23:26, Gary Herron wrote: >> On 06/21/2013 02:17 PM, Yves S. Garret wrote: >>> 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) > <...> >>> 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) >> >> 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) > > Hear, Hear. > > But really, you should be using .format by now :P > > My favourite way would be along the lines of: > > message = "Item wrote to MongoDB database " > message += "{0[MONGODB_DB]}/{0[MONGODB_COLLECTION]}".format(settings) > log.msg(message, level=log.DEBUG, spider=spider) > I'm sticking with C style formatting, which thankfully isn't going away, .format indeed. -- "Steve is going for the pink ball - and for those of you who are watching in black and white, the pink is next to the green." Snooker commentator 'Whispering' Ted Lowe. Mark Lawrence