Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'string.': 0.04; 'syntax': 0.04; 'result,': 0.05; 'referring': 0.07; 'be:': 0.09; 'formatting': 0.09; 'itself,': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.10; 'subject:python': 0.11; '>>>': 0.14; 'eval': 0.16; 'evaluating': 0.16; 'from:addr:lanyjie': 0.16; 'from:name:yingjie lan': 0.16; 'okay': 0.16; 'received:124.205': 0.16; 'reply-to:addr:lanyjie': 0.16; 'reply-to:name:yingjie lan': 0.16; 'yingjie': 0.16; 'refers': 0.17; 'string,': 0.17; 'this:': 0.17; 'string': 0.19; 'example': 0.19; 'controlled': 0.21; 'differ': 0.21; 'mechanism': 0.21; 'header:In-Reply-To:1': 0.22; 'raw': 0.23; 'variable': 0.23; 'cc:2**0': 0.26; 'realize': 0.26; 'function': 0.26; 'common': 0.28; 'cc:addr:python.org': 0.28; 'question': 0.28; 'password.': 0.28; 'strings,': 0.28; 'subject:skip:i 10': 0.28; 'reply-to:addr:yahoo.com': 0.28; "skip:' 10": 0.29; 'like:': 0.32; 'could': 0.32; 'really': 0.33; 'turn': 0.33; 'break': 0.34; 'called': 0.34; 'getting': 0.35; 'characters': 0.35; 'there': 0.36; 'another': 0.36; 'but': 0.37; 'say': 0.37; 'comments': 0.37; 'dynamic': 0.37; 'subject:: ': 0.37; 'sense': 0.37; "didn't": 0.38; 'from:': 0.38; 'under': 0.38; 'old': 0.38; 'allow': 0.40; '...': 0.40; 'said': 0.40; "won't": 0.40; 'show': 0.61; 'skip:$ 10': 0.62; 'kind': 0.63; 'back': 0.63; 'more': 0.63; 'here': 0.64; 'risk': 0.65; 'header:Reply-To:1': 0.67; 'safe': 0.68; 'below.': 0.68; 'increase': 0.70; "'it": 0.84; 'calls,': 0.84; 'distinguish': 0.84; 'hood': 0.84; 'hunt': 0.84; 'received:98.138.90.51': 0.84; 'received:98.138.91.35': 0.84; 'received:nm28-vm1.bullet.mail.ne1.yahoo.com': 0.84; 'proposal,': 0.91; 'received:98.138.226': 0.91; 'to:addr:hotmail.com': 0.98 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 148483.94051.bm@omp1063.mail.ne1.yahoo.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1333351461; bh=+OrMeSFXIiU3y8sQqKTgFR4it4mUtwn46xmAb5/my70=; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=YCvju1EadLgYdc0p8mbVs+YJ+cyQAI7TSqTGtYy5weHiA/sTaaEnVe6vZj9EI7CdJmgrJNiIOwFJPbbZElctzGGTBMDhN/YGIJQXQ+KVopwwq9RSPgRv+bVC3TYiKYTYIpn3h6ll6BoGZy5rgQiqqqZ4osklH+I2/DazeGrI3LE= 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:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=iniP1YEElEi3L+u1dRFIJFpxHj+QOgMKiQSognUF7kdw5ZIShSm6C+dPR3641WB1c0VkTho2hHYMARGclzCOWcMs4Km7ETNvSOGdILgo/5ylS/nK9gXX1t1gU6o8+ywn/A80K2EuTYHOOxNrjPrMKNckn5zIbYfuD0gukSzTsqM=; X-YMail-OSG: lkqutuYVM1njZ7RlQ5gauLlJLYCfvpPo28f.ol0R4VYlE9F M9h9ivV3uEEBo4zpMSnMbIMVlJDgyeIDhbupFQWcTgVVj.Cfmy10O7eFCbsz HxCKBscKtol9IhKMlX9UAT7IVHNGq4Mby9rxnFVNr8DA3sXCfVAc1Jt1Me11 8XW2g2m4BWtS486158e1vh.K3Ca12..TJLWgZHlJCidWr9vPGHmu4YQGoJSo EEBpiaM2A2mltVPhxWKAttxTlUgQbNZwv3B2Y3Vi1177SQAI2rL6rYsIVXBq 2hRb0GGPA3QJXbtJntNv3b0GVxStaGTgr5Jc41YBK14VfEX8.BJP6yS37VdN Stp5i71vTizjkQeowmoPv7ZlZr5SsGbFP.h8S3.7WySpUOpb1mqWLbd7MG3G znHt9C7S6Ko8_X0pIrRmixBfM.nRXegaYy0qY_LQjFQzpJ.xp6l9cZYolPAG Ebi16hLZ2O10o4H2ORZT2dDU- X-Mailer: YahooMailWebService/0.8.117.340979 References: , , <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> Date: Mon, 2 Apr 2012 00:24:21 -0700 (PDT) From: Yingjie Lan Subject: Re: string interpolation for python To: Adrian Hunt In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: python-list 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1333351470 news.xs4all.nl 6960 [2001:888:2000:d::a6]:39380 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22441 Hi Adrian, see my comments below.=0A>________________________________=0A> F= rom: Adrian Hunt =0A...=0A>It could break old code...= okay you may say you should=E2=80=99nt allow =0A>certain characters but if= they're printable and used in a controlled=0A>environment those characters= can dramatically increase the security=0A>of a username and password.=0A= =0A=0AWhat you said makes lots of sense to me.=C2=A0=0Aif strings are inter= polated *automatically*.=0A=0ABut it won't and shouldn't.=0A=0AThey are cal= led "Dynamic strings".=0ADynamic strings can achieve formatting,=C2=A0=0Abu= t the mechanism under the hood differ=0Afrom common strings dramatically.= =0A=0AMany here didn't realize that this is not=0Aanother formatting propos= al, it is a new=0Akind of *expression*.=C2=A0=0A=0ATo have it in Python, we= will need=C2=A0=0Aa new kind of syntax to distinguish it=0Afrom other stri= ngs, such as=C2=A0raw strings=C2=A0=0Aand the like. A raw string=C2=A0looks= like:=0A=0A>>> r'my\\ raw str'=0A'my\\\\ raw str'=0A=0AA dynamic string ma= y look like this:=0A=0A>>> name =3D "Peter" #common string=0A>>> d"Thank yo= u, $name$!" #dynamic string!=0A'Thank you, Peter!'=0A=0A=0AThe following ex= ample would make it feel=C2=A0=0Aa lot more safe (suppose a =3D raw_input()= ):=0A=0A>>> a =3D=C2=A0'd"Are you $name$?"'=0A>>> print(a)=0A'd"Are you $na= me$?"'=0A=0A>>> eval('d"Are you $name$?"')=0A=0A'Are you Peter?'=0A>>> d"It= contains $len(_.split())$ words!"=0A'It contains 3 words!'=0A=0AAn interes= ting question might be:=0Awhat if a dynamic string is referring=0Ato anothe= r dynamic string, which=0Ain turn refers back to the former?=0A=0AThe answe= r is: no variable can hold=0Aa dynamic string itself, only its result,=0Awh= ich can only be a common string.=0A=0AHowever, a infinite recursion may=C2= =A0=0Aoccur if the eval function is used inside:=0A=0A>>> a =3D 'd"$eval(a)= $"'=0A>>> eval(a)=0A=0AThis is just to show a dynamic string=0Ais really an= expression in disguise.=0ALike evaluating any expression containing=0Afunc= tion calls, there is risk of getting into=0Ainfinite recursion.=0A=0ACheers= ,=C2=A0=0A=0AYingjie