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


Groups > comp.lang.python > #22456

Re: string interpolation for python

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'encouraging': 0.07; 'false.': 0.07; 'skip:% 20': 0.07; 'python': 0.09; '>>>>': 0.09; 'alternatives': 0.09; 'formatting': 0.09; 'identifier': 0.09; 'skip:$ 30': 0.09; 'subject:string': 0.09; 'tuple.': 0.09; 'cc:addr:python-list': 0.10; 'mon,': 0.11; 'template': 0.11; 'subject:python': 0.11; 'ideal': 0.12; '"are': 0.16; 'evaluating': 0.16; 'expressions,': 0.16; 'hostile.': 0.16; 'magic': 0.16; 'personally,': 0.16; 'used:': 0.16; 'yingjie': 0.16; 'tend': 0.17; 'string': 0.19; 'wrote:': 0.19; 'url:02': 0.21; 'header:In-Reply- To:1': 0.22; 'towards': 0.24; 'message-id:@mail.gmail.com': 0.24; 'cheers,': 0.26; 'non': 0.26; 'received:209.85.212.46': 0.26; 'cc:2**0': 0.26; 'cc:addr:python.org': 0.28; 'concern': 0.28; 'now?': 0.28; 'skip:$ 20': 0.28; 'subject:skip:i 10': 0.28; 'practical': 0.30; 'chris': 0.31; 'received:209.85.212': 0.32; 'received:209.85': 0.32; 'received:google.com': 0.32; 'am,': 0.34; 'things': 0.35; 'received:209': 0.35; 'legitimate': 0.35; 'url:org': 0.35; 'but': 0.37; 'community': 0.37; 'why': 0.37; 'dynamic': 0.37; 'subject:: ': 0.37; 'some': 0.39; 'header:Received:5': 0.40; 'relatively': 0.62; '2012': 0.62; 'more': 0.63; 'url:2011': 0.72; 'to:addr:yahoo.com': 0.82; 'based,': 0.84; 'conservative': 0.84; 'dict,': 0.84; 'hostile': 0.84; 'proposal.': 0.84; 'sender:addr:chris': 0.84; 'similar)': 0.84; 'technique': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=h41uBTLuJMVDt9USn3f2aVmmeInDL/hP2/h2lqXMQt8=; b=bxjZmkr5pyuzPhcRKIe80h13EzfGAxJ370KmwaWgUXaVa2YfNFNI5VKe7jz4oso7FI nZFG9oF19+KJaYKFSHxL7X48RmMa8rc1eNRmMcVLqKfasG2zwl0csTMGzKxknvN1+tef Mi2Vr8zS6I/TBe+u+l6pvdc+1W3JK4ASw16yo=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=h41uBTLuJMVDt9USn3f2aVmmeInDL/hP2/h2lqXMQt8=; b=lYXCqI28ynh+z3vEqAh3Us76rVdWT+/AXYlKf9tCtnW+lp7BH2xIXzpQFXB+CpAEu1 pqQmQksnPYMLovhCBRZBcNsfNoSHWSBbxvycYlmGJHNOAIk7rhn2i1DCmbWPvX2hweOG OSDPyctlbOfsliRz/KgtLQ8EvwmogWb2dHunFKtRo7PzHtOK69MeU8CfTj6C4iY/4t9i 4Hb32zWR41re/YC0nW1bBYAmPNI6fP30z63hWQJv0zOP6qoAl2fyFhyfAreSd/vp/Ef5 hStQXu6iSXWAciNL/GH9FN4HrhCcImhWEKI1SVRx5wcMaqHLyh96s1jy6kS7u4873GMP SxGQ==
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com>
References <CABgq=FyhR+Ldujj3YKRBpVXRVoeoayuXZviUUcNx-gXnFiHLSw@mail.gmail.com> <CACoeR0xV=28j6rFHm1ep3gzH9C0sbDqyxRRwX-JrVm3G+rrXww@mail.gmail.com> <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <jl6ma0$ptg$1@dough.gmane.org> <mailman.1200.1333352587.3037.python-list@python.org> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <1333357906.6147.YahooMailNeo@web121503.mail.ne1.yahoo.com>
Date Mon, 2 Apr 2012 03:23:15 -0700
X-Google-Sender-Auth 7gGr0EGUcIo65vos6pCrLPSoepw
Subject Re: string interpolation for python
From Chris Rebert <clp2@rebertia.com>
To Yingjie Lan <lanyjie@yahoo.com>
Content-Type text/plain; charset=UTF-8
X-Gm-Message-State ALoCoQmtq53/5pMDvVTdiUsIoCYy2AxigH/Nst0NyqYQq9bMlhhh1/+sy8h7zfZ35oxcrd2ZzrKA
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.1208.1333362204.3037.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1333362204 news.xs4all.nl 6923 [2001:888:2000:d::a6]:34154
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:22456

Show key headers only | View raw


On Mon, Apr 2, 2012 at 2:11 AM, Yingjie Lan <lanyjie@yahoo.com> wrote:
<snip>
> I believe non of the other three alternatives are as terse and readable.
> We've got template based, formatting with dict, formatting with tuple.
> They all require the coder extra effort:
>
> Both template based and dict-based formatting require writing the
> identifier three times:

False. Only once is required, though the technique to achieve it is kinda hacky.

>>>> name = 'Peter'
>>>> "Are you %(name)s"%{'name':name}

"Are you %(name)s" % locals() # or vars()

> If dynamic string is used:
>>>> "Are you $name$?"
>
> Template:
>>>> Template("Are you $name?").substitute(name=name)

Template("Are you $name?").substitute(locals()) # or vars()

> It is three to one in compactness, what a magic 3!
<snip>
> Why the Python community is so
> hostile to new things now?

It's more conservative than hostile. Here's some insight:
http://www.boredomandlaziness.org/2011/02/status-quo-wins-stalemate.html

Personally, in isolation, the only part of your proposal I find
/truly/ objectionable is the support for arbitrary expressions, since
it would tend towards encouraging suboptimal factoring. But we also
don't live in an ideal world, so the existence of the other 3 (2 of
them particularly relatively similar) alternatives is a legitimate
practical concern when evaluating your proposal. Python is
middle-aged; it's a blessing and a curse.

Cheers,
Chris

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


Thread

Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 00:39 -0700
  Re: string interpolation for python Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-04-02 11:01 +0300
  Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 08:26 +0000
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-02 18:47 +1000
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 02:11 -0700
      Re: string interpolation for python Duncan Booth <duncan.booth@invalid.invalid> - 2012-04-02 10:19 +0000
      Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 11:54 +0000
        Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 05:40 -0700
          Re: string interpolation for python Laurent Claessens <moky.math@gmail.com> - 2012-04-02 15:02 +0200
            Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 07:25 -0700
            Re: Re: string interpolation for python Evan Driscoll <driscoll@cs.wisc.edu> - 2012-04-02 15:36 -0500
          Re: string interpolation for python mwilson@the-wire.com - 2012-04-02 10:46 -0400
            Re: string interpolation for python mwilson@the-wire.com - 2012-04-02 11:34 -0400
              Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 09:02 -0700
      Re: string interpolation for python rusi <rustompmody@gmail.com> - 2012-04-02 06:04 -0700
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 02:17 -0700
      Re: string interpolation for python alex23 <wuwei23@gmail.com> - 2012-04-02 22:47 -0700
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-02 19:56 +1000
    Re: string interpolation for python Chris Rebert <clp2@rebertia.com> - 2012-04-02 03:23 -0700
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 04:46 -0700
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 05:00 -0700
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-03 00:58 +1000
      Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 18:56 +0000
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 08:49 -0700
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-03 08:38 +1000
      Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 23:18 +0000
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 18:57 -0700

csiph-web