Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #48924 > unrolled thread

Re: n00b question on spacing

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2013-06-22 15:40 +0100
Last post2013-06-22 15:40 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: n00b question on spacing Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-06-22 15:40 +0100

#48924 — Re: n00b question on spacing

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-06-22 15:40 +0100
SubjectRe: n00b question on spacing
Message-ID<mailman.3694.1371912044.3114.python-list@python.org>
On 22/06/2013 14:36, Joshua Landau wrote:
> On 21 June 2013 23:26, Gary Herron <gherron@digipen.edu> 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web