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: 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: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <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 To: Yingjie Lan Content-Type: text/plain; charset=UTF-8 X-Gm-Message-State: ALoCoQmtq53/5pMDvVTdiUsIoCYy2AxigH/Nst0NyqYQq9bMlhhh1/+sy8h7zfZ35oxcrd2ZzrKA Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Mon, Apr 2, 2012 at 2:11 AM, Yingjie Lan wrote: > 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! > 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