Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'issue,': 0.05; 'correct.': 0.07; 'expressions': 0.07; 'skip:% 20': 0.07; 'python': 0.09; '>>>>': 0.09; 'alternatives': 0.09; 'formatting': 0.09; 'identifier': 0.09; 'subject:string': 0.09; 'tuple.': 0.09; 'mon,': 0.11; 'template': 0.11; 'subject:python': 0.11; 'itself.': 0.12; '>>>': 0.14; '"are': 0.16; '"well,': 0.16; '(and,': 0.16; 'double-quote': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'magic.': 0.16; 'notation,': 0.16; 'perfect.': 0.16; 'substitute': 0.16; 'syntactic': 0.16; 'used:': 0.16; 'way:': 0.16; 'yingjie': 0.16; 'string': 0.19; 'wrote:': 0.19; 'allows': 0.20; 'plus.': 0.21; 'header:In-Reply-To:1': 0.22; 'demonstrate': 0.23; 'hey': 0.23; 'message-id:@mail.gmail.com': 0.24; 'non': 0.26; 'sequence': 0.27; 'now?': 0.28; 'proposing': 0.28; 'subject:skip:i 10': 0.28; 'especially': 0.28; 'received:209.85.210.174': 0.30; 'received:mail- iy0-f174.google.com': 0.30; 'supported': 0.30; 'skip:b 20': 0.30; 'requirement': 0.31; 'received:209.85': 0.32; 'received:google.com': 0.32; 'received:209.85.210': 0.33; 'pm,': 0.34; 'massive': 0.34; 'to:addr:python-list': 0.35; 'things': 0.35; 'received:209': 0.35; 'there': 0.36; 'does': 0.36; '(with': 0.36; 'languages': 0.36; 'being': 0.36; 'but': 0.37; 'community': 0.37; 'far': 0.37; 'say': 0.37; 'why': 0.37; 'dynamic': 0.37; 'subject:: ': 0.37; 'instead': 0.38; 'old': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'sure': 0.40; 'quite': 0.40; '2012': 0.62; 'more': 0.63; 'dollar': 0.71; 'based,': 0.84; 'defensive': 0.84; 'dict,': 0.84; 'differences,': 0.84; 'everything.': 0.84; 'hostile': 0.84; 'personally.': 0.84; 'spite': 0.84; 'careful': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=JeEhNySwGfs6oQdZddbrSL1nrgB54LrToLuDyqhMgpU=; b=nqWRwklqEY4RboA8QSAiyA8XRra2F+Ppmm6g6wLj+iUid2MzFezJZ8osHJQ5o8WW39 KHDypcsDl9Md/xrt9O4Kk4y/4XEfUT54+/J9Bpv55OkcDdfuKCrO3qz/5hpOzOuoU5rB 77m6fiY/XjnQVnGASPfiv/Kjjc+faSYkMHe9uxKoF5yzgMEdfqZ4E67pJmwydxqG2ulu BVlRncu9MLriMX1rRXiIoQqyrBPP5rIQDEiHZjim4/Thzr20R54duNRKx5ekD2oftsIQ 5EnCaXe/MDOzzsVHWK4KzTk4PLkHjtLoxccaoqFT65kOo0BvCMtj7eVOUQBbWPxZ3u3y E/mg== MIME-Version: 1.0 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 19:56:27 +1000 Subject: Re: string interpolation for python From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1333360590 news.xs4all.nl 6847 [2001:888:2000:d::a6]:51980 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22453 On Mon, Apr 2, 2012 at 7:11 PM, 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: > >>>> name =3D 'Peter' >>>> "Are you %(name)s"%{'name':name} > > If dynamic string is used: >>>> "Are you $name$?" Yes, it's more compact. But it's also more magic. However, there's an alternative that's almost as compact. The only requirement is that you use a two-character token instead of your dollar sign: a double-quote and a plus. >>> "Are you "+name+"?" That allows arbitrary expressions and everything. > Of course, the old C style way: > >>>> "Are you %s?"%name > > Almost as terse, but not as readable, especially > when there are many=A0parts to substitute -- > the coder and reader need to be careful > to=A0make sure the sequence is correct. I quite like this notation, personally. It's convenient, and is supported (with variants) in quite a few C-derived languages (and, in spite of the massive syntactic differences, Python does have C heritage). > Why the Python community is so > hostile to new things now? > Python has merits, > but it is far from being perfect. Hey now, no need to get defensive :) Thing is, it's up to you to demonstrate that your proposal justifies itself. You're proposing to create a massive backward-compatibility issue, so you need to prove that your new way of formatting strings is sufficiently awesome to be able to say "Well, you need Python 3.4+ to use this". ChrisA