On 22/06/2013 14:36, Joshua Landau wrote:
On 21 June 2013 23:26, Gary Herron <gher...@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
--
http://mail.python.org/mailman/listinfo/python-list