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) -- http://mail.python.org/mailman/listinfo/python-list