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


Groups > comp.lang.python > #48922

Re: n00b question on spacing

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joshua.landau.ws@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.033
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'msg': 0.09; 'skip:% 20': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'wrote': 0.14; 'splitting': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'message- id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'along': 0.30; 'lines': 0.31; 'gary': 0.31; 'really,': 0.31; "i'd": 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'skip:" 50': 0.36; 'should': 0.36; 'pm,': 0.38; 'how': 0.40; 'of:': 0.68; 'clearer': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=Rn9HsQbtreo2UsBUt9ccUiIYTP6oxPYFb9liuoaRAQM=; b=JCcmSLuNqBj69ZZCO3SMQjXuPoKq8wpUDVrrwKyReeUzAg4vKbmHWrEzMK7y/2fcus lkuB6L3EK6PtizNaA4tJ4CPzYFJy1STvExc7/WGi8mXFgvhTTQ7Hc0+TurEw3cNvWqdK etIomXnftRTdMrTjvGIBSpnUS6wDmi0u5IJacydhdjyX3G5VqIQjOaqqEOKMV4zufXX4 VzCJqskdUvHPRkadT5E1w402yH/huzv15emmEO92hHwSh6RJyxeeKwo7y3XUzNUG0S34 F2MGDmv9SSMLi+Jh406Jjqac40YWblebY3FAFBFqY2/UHv/ZYHWVNvPboJysKI3okC/y 1CaA==
X-Received by 10.152.4.232 with SMTP id n8mr7957727lan.29.1371908244057; Sat, 22 Jun 2013 06:37:24 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <51C4D2FF.8000709@digipen.edu>
References <CAJ=2b07ETuSuo2+3Xu6vMOJA+q1JwUFTezO3LaYLG8wXd+FLBQ@mail.gmail.com> <51C4D2FF.8000709@digipen.edu>
From Joshua Landau <joshua.landau.ws@gmail.com>
Date Sat, 22 Jun 2013 14:36:43 +0100
Subject Re: n00b question on spacing
To Gary Herron <gherron@digipen.edu>
Content-Type text/plain; charset=UTF-8
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3692.1371908252.3114.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371908252 news.xs4all.nl 15887 [2001:888:2000:d::a6]:43683
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48922

Show key headers only | 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