Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.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; "wouldn't": 0.03; 'dict': 0.09; 'fetch': 0.09; 'formatting': 0.09; 'subject:string': 0.09; 'subject:python': 0.11; '>>>': 0.14; 'to:name:python- list@python.org': 0.14; 'attribute,': 0.16; 'bit.': 0.16; 'formatting,': 0.16; 'from:addr:lanyjie': 0.16; 'from:name:yingjie lan': 0.16; 'message-id:@web121502.mail.ne1.yahoo.com': 0.16; 'received:124.205': 0.16; 'reply-to:addr:lanyjie': 0.16; 'reply- to:name:yingjie lan': 0.16; 'skip:{ 30': 0.16; 'string': 0.19; 'print': 0.21; 'header:In-Reply-To:1': 0.22; 'bit': 0.22; 'class': 0.25; 'subject:skip:i 10': 0.28; 'reply-to:addr:yahoo.com': 0.28; 'there.': 0.28; 'format,': 0.32; 'really': 0.33; 'to:addr:python- list': 0.35; 'things': 0.35; 'skip:{ 10': 0.35; 'doing': 0.36; 'say': 0.37; 'dynamic': 0.37; 'object': 0.37; 'subject:: ': 0.37; 'instead': 0.38; 'anything': 0.38; 'old': 0.38; 'to:addr:python.org': 0.39; '...': 0.40; 'header:Reply-To:1': 0.67; 'dict,': 0.84 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 356006.34593.bm@omp1056.mail.ne1.yahoo.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1333376732; bh=GyISA5WrjAU1d8eTAybgBpupLAmwFqP5IBkVEKrb0Nc=; 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=GSTEKm46YaLVGpUJ7fpv0CIpMAiVyXr3d6rP637aImq0SR0zuWSJ5XpMkFKk2lf5FT2mvNgcSIun3c8BYOtpWMbhbxS/3BvI4BiyRNX8vc96oYKqJMXXaRDje8unKHOn+hAnvHvUpD/k7YNpo46Vfgc/cGY5vqX3MODHVuB1hNI= 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=Dc2X3owaHqoFdY4O4qTNrc20gFG1CHObvApeq+mPL0n2bZ7WFV/fUR02H2I8w1nnr3wJv/WYBHr0ffy4JXPastDU4ge4hEM3m/o4RvC6BdmaDy/HSgw9leM647YhooC3AinusUiA+a6cVK6sGJrDw83TbpzIcDgnp+E4/1lWIZY=; X-YMail-OSG: ZX68w9IVM1kWm565KMUyosatMFWQR2kdLn.Ps7LAlAYT5Lo LneLpqiukOzhKJ4K0udSzXNk87Mn8Ih6sv0gfDCAtQUEbJpWeUnd2iJoOFfC 5p5FEm_1bM_W5ZJs0IboICDWCQbtggiNZeLqgrB8uuTGFIclziMDXNQ6ZGNj 77kzZaf8l6t1qiqYR8iLxRHOKKFDa5I3OoAZVjWUQNQW0IaNPoU3KZyQQIBM Zkpw.09X3Q16j_WaEXNW7gebfjBY12baOYqCuTOtNRSpiWIjxgVsQEDs6qzD EJB5gjySXybYp0uZioka0ABSPXPZR4ezEiZCAcaECsxsbfWFF27qV6HyxEpf Jk_edOSWif2uALiEf6LqGeLup1tEvXRr8zMBGGn3uhKhCsnlthJuiK6tcj1v OoMAPEbNSJ8oroyuXOv8FTuytmwvEO8ccG34nzeGBEjxc.DB9gfPsC7pYWks 4Egcj_Euadou6CeXZMKQfi1_nO56kqN6g4St6XD93dqZ.2_DfrauLK3XWEUM f0OD7nVjBBKQ.HLd8p6OFv1yp2O.YFrc1GPK0YeLaumhvz3UT5iYzIxSD X-Mailer: YahooMailWebService/0.8.117.340979 References: <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 2 Apr 2012 07:25:32 -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: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1333376735 news.xs4all.nl 6953 [2001:888:2000:d::a6]:36299 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22468 > like this one ?=0A=0A> =0A> b =3D dict(name=3D"Sue", job=3D"SAS sharp-sho= oter")=0A> print "$b['name']$ works as b['job']"=0A> =0A> Is it really easi= er to read that the following ?=0A> "{0} works as {1}".format(b['name'],b['= job'])=0A> =0A> In the case in which b is an object having "job" and "name"= =0A> attribute, the dynamic string will write=0A> =0A> "$b.name$ works as = $b.job$"=0A> instead of=0A> "{0}.name works as {0}.job".format(b)=0A> =0A= =0A=0AWhen you already have a dict, the dict-based=0Aformatting would be ni= ce.=0A=0A>>> "%(name)s works as %(job)s"%b=0A=0AIf it you need to create a = dict just for string=0A=0Aformatting, dynamic string would be nice.=0ASay y= our object has methods/properties=0Athat fetch things from your database.= =0A=0A>>> class staff:=0A...@property=0A...def name(): return 'Peter'=0A...= =0A>>> t =3D staff()=0A>>> vars(t)=0A{}=0A>>> t.name=0A'Peter'=0A>>> d"Staf= f name: $t.name$" #note the d"..." format=0A'Staff name: Peter'=0A=0ABecaus= e of the d"..." format, it won't=A0=0Aaffect old ways of doing things one b= it.=0AAllowing dynamic string wouldn't hurt=A0=0Aa bit to anything that is = already there.