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


Groups > comp.lang.python > #48939

Re: n00b question on spacing

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; ';-)': 0.03; 'syntax': 0.04; 'argument': 0.05; 'preference': 0.07; '22,': 0.09; 'wrapper': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'def': 0.12; 'wrote': 0.14; 'construct.': 0.16; 'help?': 0.16; 'illegal,': 0.16; 'key):': 0.16; 'mark.': 0.16; 'skip:" 70': 0.16; 'skip:{ 30': 0.16; 'skip:{ 40': 0.16; 'slip': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'settings': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'skip:{ 20': 0.24; 'string,': 0.24; 'tend': 0.24; 'cc:2**0': 0.24; 'options': 0.25; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'words': 0.29; 'said,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'lines': 0.31; '+0100,': 0.31; '>>>>': 0.31; 'class': 0.32; 'probably': 0.32; 'skip:m 30': 0.32; 'quite': 0.32; 'skip:_ 10': 0.34; 'could': 0.34; 'problem': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'johnson': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'wrong': 0.37; 'too': 0.37; 'rather': 0.38; 'even': 0.60; 'skip:u 10': 0.60; 'forum': 0.61; "you're": 0.61; 'first': 0.61; "you'll": 0.62; 'real': 0.63; 'myself': 0.63; 'within': 0.65; 'it!': 0.67; '(oh': 0.84; 'misses': 0.84; 'nice,': 0.84; 'to:addr:ntlworld.com': 0.84; 'do:': 0.91; 'good,': 0.91; 'rick': 0.93; '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:content-transfer-encoding; bh=nr8oQpelCqAfXpj4T7njCw4BtU58i+qtMdHxVE5Y2I0=; b=0nEP9HjlxucyCq2GkMmBxnW4rXZAGe63IcTAG7Is0brugqIxwjhlZp7qluBhNkXrdB mMW+y4b70ZQHzO+TDMFqsuMlyvmXPS3t+Sv2uRcqjey/MB9M+J6Ai9ynxFAM3LkVvsFK YOtXMd2eObHKdxde3nnziEli3IffkB8Tlqoav8UFBXrW94bxsDBacAux0IyMTIGHZpQe K3JyiaqlkblnvSeHxxFcSSTzRMYISzZYg5svM9XEh307v8k9M6BkHt/gMEg4GdSrtp/D UMRHXiGtCMzljWQ30IeKprwmFEHmj1NpEB5rqcOAKHTUXG7gbgky4KXXUR7bhbtNUbyi jsGA==
X-Received by 10.112.42.44 with SMTP id k12mr5972166lbl.63.1371925262815; Sat, 22 Jun 2013 11:21:02 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <f9lxt.156155$tu1.23696@fx20.am4>
References <f9lxt.156155$tu1.23696@fx20.am4>
From Joshua Landau <joshua.landau.ws@gmail.com>
Date Sat, 22 Jun 2013 19:20:22 +0100
Subject Re: n00b question on spacing
To Alister <alister.ware@ntlworld.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
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.3702.1371925271.3114.python-list@python.org> (permalink)
Lines 87
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1371925271 news.xs4all.nl 15988 [2001:888:2000:d::a6]:54037
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:48939

Show key headers only | View raw


On 22 June 2013 18:28, Alister <alister.ware@ntlworld.com> wrote:
> On Sat, 22 Jun 2013 17:11:00 +0100, Joshua Landau wrote:
>
>> On 22 June 2013 16:55, Rick Johnson <rantingrickjohnson@gmail.com>
>> wrote:
>>> On Saturday, June 22, 2013 10:40:24 AM UTC-5, Joshua Landau wrote:
>>>> > Plus, your use of the format syntax is incorrect.
>>>> Wut?
>>>
>>> Well what i mean exactly is not that it's illegal, i just find the use
>>> of the "getattr sugar", from WITHIN the format string, to be
>>> excessively noisy.
>>
>> Sure...
>> So in other words you realised you were wrong but you're too scared to
>> admit it. Eh? That's it, isn't it! You just don't want to loosen your
>> proud persona :P.
>
> In this argument I tend to find myself siding with Rick.
> Considering his general reputation in this forum am I missing something
> or do I need help? ;-)

I wasn't mocking the preference against it, but rather that that was
completely not what he said originally. One cannot let slip when the
mighty Rick misses his mark.

That said, yes, it is quite a noisy construct. I still prefer it to:

message = "Item wrote to MongoDB database {}/{}"
message = message.format(
        settings['MONGODB_DB'],
        settings['MONGODB_COLLECTION']
)
log.msg(message, level=log.DEBUG, spider=spider)

Because this feels undescriptive - the first and "second" lines feel
detached. Instead of Rick's hilarious unpacking, you could always do:

message = "Item wrote to MongoDB database {database}/{collection}"
message = message.format(
        database=settings['MONGODB_DB'],
        collection=settings['MONGODB_COLLECTION']
)
log.msg(message, level=log.DEBUG, spider=spider)

Which is probably as good, if longer. You'll see the real problem is
that "MONDODB_DB" and "MONGODB_COLLECTION" are awful names; would you
really have so detested

message = "Item wrote to MongoDB database "
message += "{settings[database]}/{settings[collection]}".format(settings=settings)
log.msg(message, level=log.DEBUG, spider=spider)

or even, now,

message = "Item wrote to MongoDB database
{settings[database]}/{settings[collection]}"
message = message.format(settings=settings)
log.msg(message, level=log.DEBUG, spider=spider)

?

I think those options are quite nice, รก mon avis. I could even write a
wrapper (oh noes!):

# Shortened for EMail
class SettingsWrapper:
    def uglify_key(self, key): return key if key.startswith("MONGODB")
else "MONGODB_" + key.upper()
    def __init__(self, settingsdict): self.wrapped = settingsdict
    def __len__(self): return self.wrapped.__len__()
    def __iter__(self): return self.wrapped.__iter__()
    def __getitem__(self, key): return self.wrapped[self.uglify_key(key)]
    def __contains__(self, key): return self.uglify_key(key) in self.wrapped
    def __setitem__(self, key, value):
self.wrapped[self.uglify_key(key)] = value
    def __delitem__(self, key, value): del self.wrapped[self.uglify_key(key)]

settings = SettingsWrapper(settings)

message = "Item wrote to MongoDB database {settings[db]}/{settings[collection]}"
message = message.format(settings=settings)
log.msg(message, level=log.DEBUG, spider=spider)

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


Thread

Re: n00b question on spacing Alister <alister.ware@ntlworld.com> - 2013-06-22 17:28 +0000
  Re: n00b question on spacing Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-22 19:20 +0100

csiph-web