Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'syntax': 0.04; 'escape': 0.07; 'executable': 0.07; 'expressions': 0.07; 'objects,': 0.07; 'parser': 0.07; 'strings.': 0.07; 'suppose': 0.07; 'python': 0.09; 'curve': 0.09; 'formatting': 0.09; 'notation': 0.09; 'objects.': 0.09; 'page?': 0.09; 'skip:k 40': 0.09; 'subject:string': 0.09; 'subject:python': 0.11; '>>>': 0.14; 'essential': 0.14; 'to:name :python-list@python.org': 0.14; 'benefit.': 0.16; 'eval': 0.16; 'from:addr:lanyjie': 0.16; 'from:name:yingjie lan': 0.16; 'performance,': 0.16; 'received:124.205': 0.16; 'reply- to:addr:lanyjie': 0.16; 'reply-to:name:yingjie lan': 0.16; 'syntax.': 0.16; 'yingjie': 0.16; 'have:': 0.17; 'string': 0.19; 'least': 0.20; 'maybe': 0.22; 'header:In-Reply-To:1': 0.22; 'otherwise,': 0.23; 'that.': 0.24; 'cheers,': 0.26; 'right.': 0.26; 'skip:> 10': 0.27; 'translated': 0.27; 'seems': 0.27; 'common': 0.28; 'consequence': 0.28; 'issues.': 0.28; 'strings,': 0.28; 'subject:skip:i 10': 0.28; 'though.': 0.28; 'turns': 0.28; 'reply-to:addr:yahoo.com': 0.28; "i'm": 0.29; 'embedded': 0.30; 'list.': 0.31; 'possibly': 0.31; "aren't": 0.32; 'code': 0.32; 'could': 0.32; 'really': 0.33; 'method': 0.33; 'next': 0.34; 'meaning': 0.34; 'mean': 0.34; 'to:addr:python-list': 0.35; 'done': 0.35; 'list': 0.35; 'paying': 0.35; "skip:' 20": 0.35; 'skip:m 40': 0.35; 'does': 0.36; 'editor': 0.36; 'being': 0.36; 'ones': 0.37; 'but': 0.37; 'dynamic': 0.37; 'object': 0.37; 'subject:: ': 0.37; 'possible.': 0.37; 'skip:s 20': 0.37; 'performance': 0.38; 'too': 0.39; 'to:addr:python.org': 0.39; 'where': 0.39; 'allow': 0.40; '8bit%:8': 0.40; 'past': 0.40; 'learning': 0.60; '(that': 0.62; 'worth': 0.62; 'kind': 0.63; 'more': 0.63; 'here': 0.64; 'header:Reply-To:1': 0.67; 'taking': 0.68; 'lose': 0.71; 'everybody': 0.78; 'absolutely': 0.84; 'complexity': 0.84; 'difference.': 0.84; 'distinguish': 0.84; 'is\xa0': 0.84; '3.3': 0.91; 'received:98.138.226': 0.91; 'convinced': 0.93 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 973194.17742.bm@omp1066.mail.ne1.yahoo.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1333381766; bh=9/ctMPUT6tG0fn+dYomyuhlyUlVRl7aFRw+T6t7K0Ec=; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=qYM2x3HtkB1anLHuaGnezk9eQ2OWlIS3I7OhZgQE6RHs39hSiIRLmmY8GWPH02ndzioHkrKNk8UN35Se02I3hHP1CVrOQA/hZ4faE+7NlbE5I7SCVweVD4rM61EZ6jecCC8yt71kCTlKkl/jpn3lw7zBf4WDRx0gWdujKCicVfc= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=3MU68kBLR3nor0PaeP8TSf5bqJ+nICgyoNz+6KHT0npSQqPyAe2Qg/HrQ2eGTA/as0okfP+qppaPNqmdf7u+350Pir/I/QPjwFLGjQl/qLS16lc/bemcE+GQMWL0RThAmLWhaJ/rt/8n5pXsiZYc7OpAxGtWCnOzsyMz4ZSb9sE=; X-YMail-OSG: 9LZxTpQVM1kbs_kgX8nQ.ixzVxQ7tvSl13BotVwludTH8uY FJ4WhYyHGNnONKR1qoJm2_SeQu7qOu0FC6IswUiNm0jqlXZBaXarpdGjdmuR gjUcCwNv1aEATF.P5AzwQAk8h.Gi6nsv8utYsjrDPAkCCP.ebYlRcTzZYlkP KZJEjkxf6sZik1a8O_IIP_ivZq3kE2GKkqkbYH9.LDfxlObFuvV7gcYzSkt5 ookiv6DqCto.9C3U5JlEwrAlVlSZTGhSO_qs1atMmVLjm0Tkw3BOUj7sv9fj FucxWhyduVqG1GHAt2FHUYGYtxqTHeOWeAsFBbZZ2z25AYRJwIwjVFFkg0dh UPUpp58dorPVrXDTRP7TYl2xtXqU6khnwOcVfCdMDiKsdDA8MTJLfieE_Hdb aC1FYE6.fcy0StFFZO28.dQk8w1NZOZKw36OE.ff3qDizDG5.mKHf4WkGn0g svcOZ.jsY5_1o8zp8dW4mJ_s- X-Mailer: YahooMailWebService/0.8.117.340979 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> <1333367201.47465.YahooMailNeo@web121506.mail.ne1.yahoo.com> Date: Mon, 2 Apr 2012 08:49:26 -0700 (PDT) From: Yingjie Lan Subject: Re: string interpolation for python To: "python-list@python.org" In-Reply-To: MIME-Version: 1.0 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 Reply-To: Yingjie Lan 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1333381885 news.xs4all.nl 6852 [2001:888:2000:d::a6]:39705 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22475 > Right, meaning that both have the same issues=A0=0A> of performance, need= for=0A=0A> str(), etc. There's absolutely no difference.=0A=0A=0AOK, perfo= rmance. Here is a new solution:=0A=A0=0ASuppose we have a new string method= =0A=A0 =A0 str.format_join([...])=0Ataking a list of strings and objects,= =0Awith even-indexed ones being strings,=0Aodd-indexed ones being objects.= =0AEach even-indexed string *ends* with a formatting=0Aspecification for th= e next object in the list.=0AThen we can have:=0A>>>=A0d"sin($x$) =3D $ sin= (x):0.3f $"=0Aget translated to:=0A>>> ''.format_join(["sin(%s",x,") =3D %0= .3f", sin(x)])=0AThis seems to be at least as good in performance.=0A=0A=0A= > And no benefit. You lose out on syntax highlighting=A0=0A> in your editor= and=A0gain nothing.=0A=0AGain: readability, terseness, hassle-free, and po= ssibly=0Abetter performance if done right.=0A=0ASyntax highlighting: can be= done more creatively.=0AFor dynamic strings, string parts are like normal= =A0=0Astrings, but the embedded expressions are like=0Anormal expressions := )=0A=0A> =0A> sprintf("UPDATE tablename SET modified=3Dnow()%{,%s=3D:%[0]s%= } WHERE=0A> key=3D%d",array_of_field_names,primary_key_value)=0A> --> "UPDA= TE tablename SET modified=3Dnow(),foo=3D:foo,bar=3D:bar,quux=3D:quux=0A> WH= ERE key=3D1234"=0A> =0A> You're still paying for no complexity you aren't a= ctually using. =0A> It's=A0clear and readable.=0A=0AYou are really good at = that. Maybe not everybody is as=0Aexperience as you, and I suppose the lear= ning curve is=A0=0Akind of hard to climb.=0A=0A> It's powerful only if you = use eval to allow full expression syntax.=0A> Otherwise, what does it have = above str.format()?=0A=0A=0AThose expressions are embedded, you don't need = eval()=0Ato have the result though. Are we on the same page?=0A=0A> You may= well be able to get past the compatibility issues. I'm not yet=0A> convinc= ed that the new syntax is worth it, but it may be possible.=0A> =0A> Here's= a recommendation: Write a parser for your notation that turns=0A> it into = executable Python code (that is, executable in Python 3.3=0A> without any d= "..." support).=A0=0A=0AYou mean a translator?=0A=0AThe syntax is essential= for compatibility.=0AWe must distinguish dynamic strings from common strin= gs.=0AThey will live peacefully together.=A0=0A(escaping the '$' in normal = strings breaks compatibility,=A0=0Aand the consequence of forgetting to esc= ape could be=0Adisastrous, so definitely not an option).=A0=0A=0AMay be d" = is too tiny, $"..." is easier to pick out.=0A=0A=0A=0ACheers,=0AYingjie=0A