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


Groups > comp.lang.python > #48922

Re: n00b question on spacing

References <CAJ=2b07ETuSuo2+3Xu6vMOJA+q1JwUFTezO3LaYLG8wXd+FLBQ@mail.gmail.com> <51C4D2FF.8000709@digipen.edu>
From Joshua Landau <joshua.landau.ws@gmail.com>
Date 2013-06-22 14:36 +0100
Subject Re: n00b question on spacing
Newsgroups comp.lang.python
Message-ID <mailman.3692.1371908252.3114.python-list@python.org> (permalink)

Show all headers | View raw


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)

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


Thread

Re: n00b question on spacing Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-22 14:36 +0100
  Re: n00b question on spacing Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-22 08:24 -0700
    Re: n00b question on spacing Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-22 16:40 +0100
      Re: n00b question on spacing Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-22 08:55 -0700
        Re: n00b question on spacing Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-22 17:11 +0100
    Re: n00b question on spacing Chris Angelico <rosuav@gmail.com> - 2013-06-23 09:12 +1000
      Re: n00b question on spacing Rick Johnson <rantingrickjohnson@gmail.com> - 2013-06-22 17:48 -0700
        Re: n00b question on spacing Chris Angelico <rosuav@gmail.com> - 2013-06-23 12:26 +1000
    Re: n00b question on spacing Dave Angel <davea@davea.name> - 2013-06-22 19:28 -0400
    Re: n00b question on spacing Chris Angelico <rosuav@gmail.com> - 2013-06-23 09:37 +1000
    Re: n00b question on spacing Dave Angel <davea@davea.name> - 2013-06-22 19:56 -0400
    Re: n00b question on spacing Chris Angelico <rosuav@gmail.com> - 2013-06-23 10:27 +1000
    Re: n00b question on spacing Dave Angel <davea@davea.name> - 2013-06-22 20:46 -0400
    Re: n00b question on spacing MRAB <python@mrabarnett.plus.com> - 2013-06-23 02:20 +0100
      Re: n00b question on spacing Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-23 02:58 +0000
        Re: n00b question on spacing Roy Smith <roy@panix.com> - 2013-06-22 23:12 -0400
          Re: n00b question on spacing Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-23 03:22 +0000
            Re: n00b question on spacing Chris Angelico <rosuav@gmail.com> - 2013-06-23 13:36 +1000
            Re: n00b question on spacing Roy Smith <roy@panix.com> - 2013-06-23 09:43 -0400
        Re: n00b question on spacing Chris Angelico <rosuav@gmail.com> - 2013-06-23 14:09 +1000
    Re: n00b question on spacing Dave Angel <davea@davea.name> - 2013-06-22 21:35 -0400
    Re: n00b question on spacing Terry Reedy <tjreedy@udel.edu> - 2013-06-23 11:40 -0400

csiph-web