Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22468

Re: string interpolation for python

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 <lanyjie@yahoo.com>
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 <CABgq=FyhR+Ldujj3YKRBpVXRVoeoayuXZviUUcNx-gXnFiHLSw@mail.gmail.com> <CACoeR0xV=28j6rFHm1ep3gzH9C0sbDqyxRRwX-JrVm3G+rrXww@mail.gmail.com> <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com> <jl6ma0$ptg$1@dough.gmane.org> <mailman.1200.1333352587.3037.python-list@python.org> <4f7962b0$0$29981$c3e8da3$5496439d@news.astraweb.com> <mailman.1205.1333358032.3037.python-list@python.org> <4f79938c$0$29981$c3e8da3$5496439d@news.astraweb.com> <mailman.1212.1333370596.3037.python-list@python.org> <jlc8b8$fu8$1@news.univ-fcomte.fr>
Date Mon, 2 Apr 2012 07:25:32 -0700 (PDT)
From Yingjie Lan <lanyjie@yahoo.com>
Subject Re: string interpolation for python
To "python-list@python.org" <python-list@python.org>
In-Reply-To <jlc8b8$fu8$1@news.univ-fcomte.fr>
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 <lanyjie@yahoo.com>
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1216.1333376735.3037.python-list@python.org> (permalink)
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

Show key headers only | View raw


> like this one ?

> 
> b = dict(name="Sue", job="SAS sharp-shooter")
> print "$b['name']$ works as b['job']"
> 
> Is it really easier to read that the following ?
> "{0} works as {1}".format(b['name'],b['job'])
> 
> In the case in which b is an object having "job" and "name" 
> attribute, the dynamic string will write
> 
> "$b.name$ works as $b.job$"
> instead of
> "{0}.name works as {0}.job".format(b)
> 


When you already have a dict, the dict-based
formatting would be nice.

>>> "%(name)s works as %(job)s"%b

If it you need to create a dict just for string

formatting, dynamic string would be nice.
Say your object has methods/properties
that fetch things from your database.

>>> class staff:
...@property
...def name(): return 'Peter'
...
>>> t = staff()
>>> vars(t)
{}
>>> t.name
'Peter'
>>> d"Staff name: $t.name$" #note the d"..." format
'Staff name: Peter'

Because of the d"..." format, it won't 
affect old ways of doing things one bit.
Allowing dynamic string wouldn't hurt 
a bit to anything that is already there.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 00:39 -0700
  Re: string interpolation for python Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-04-02 11:01 +0300
  Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 08:26 +0000
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-02 18:47 +1000
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 02:11 -0700
      Re: string interpolation for python Duncan Booth <duncan.booth@invalid.invalid> - 2012-04-02 10:19 +0000
      Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 11:54 +0000
        Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 05:40 -0700
          Re: string interpolation for python Laurent Claessens <moky.math@gmail.com> - 2012-04-02 15:02 +0200
            Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 07:25 -0700
            Re: Re: string interpolation for python Evan Driscoll <driscoll@cs.wisc.edu> - 2012-04-02 15:36 -0500
          Re: string interpolation for python mwilson@the-wire.com - 2012-04-02 10:46 -0400
            Re: string interpolation for python mwilson@the-wire.com - 2012-04-02 11:34 -0400
              Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 09:02 -0700
      Re: string interpolation for python rusi <rustompmody@gmail.com> - 2012-04-02 06:04 -0700
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 02:17 -0700
      Re: string interpolation for python alex23 <wuwei23@gmail.com> - 2012-04-02 22:47 -0700
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-02 19:56 +1000
    Re: string interpolation for python Chris Rebert <clp2@rebertia.com> - 2012-04-02 03:23 -0700
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 04:46 -0700
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 05:00 -0700
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-03 00:58 +1000
      Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 18:56 +0000
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 08:49 -0700
    Re: string interpolation for python Chris Angelico <rosuav@gmail.com> - 2012-04-03 08:38 +1000
      Re: string interpolation for python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-04-02 23:18 +0000
    Re: string interpolation for python Yingjie Lan <lanyjie@yahoo.com> - 2012-04-02 18:57 -0700

csiph-web