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


Groups > comp.lang.python > #48924

Re: n00b question on spacing

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: n00b question on spacing
Date 2013-06-22 15:40 +0100
References <CAJ=2b07ETuSuo2+3Xu6vMOJA+q1JwUFTezO3LaYLG8wXd+FLBQ@mail.gmail.com> <51C4D2FF.8000709@digipen.edu> <CAN1F8qVk+Vor1USX0V7mS13K3rR8NyRc9Gt9KkF32RGakZJ_Kw@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3694.1371912044.3114.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web