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


Groups > comp.lang.python > #22416

Re: string interpolation for python

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 <python-python-list@m.gmane.org>
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; 'essentially': 0.05; 'formatting': 0.09; 'subject:string': 0.09; 'terry': 0.09; 'jan': 0.11; 'subject:python': 0.11; '>>>': 0.14; '"we': 0.16; 'balls': 0.16; 'formatting.': 0.16; 'received:80.91': 0.16; 'received:80.91.229': 0.16; 'received:gmane.org': 0.16; 'received:list': 0.16; 'received:verizon.net': 0.16; 'reedy': 0.16; 'yingjie': 0.16; 'string': 0.19; 'wrote:': 0.19; 'all,': 0.21; 'header:In-Reply-To:1': 0.22; "i'd": 0.23; 'idea': 0.24; 'header:User-Agent:1': 0.26; 'subject:skip:i 10': 0.28; 'code:': 0.28; 'hi,': 0.29; 'header:X-Complaints-To:1': 0.29; 'skip:b 20': 0.30; 'really': 0.33; 'method': 0.33; 'am,': 0.34; 'to:addr :python-list': 0.35; 'methods': 0.35; 'received:org': 0.36; 'subject:: ': 0.37; 'some': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'received:net': 0.60; 'share': 0.61; "'the": 0.91; 'have.': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: string interpolation for python
Date Sat, 31 Mar 2012 06:29:11 -0400
References <CABgq=FyhR+Ldujj3YKRBpVXRVoeoayuXZviUUcNx-gXnFiHLSw@mail.gmail.com> <CACoeR0xV=28j6rFHm1ep3gzH9C0sbDqyxRRwX-JrVm3G+rrXww@mail.gmail.com> <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-74-109-121-73.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0
In-Reply-To <1333174946.18436.YahooMailNeo@web121506.mail.ne1.yahoo.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
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.1177.1333189777.3037.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1333189777 news.xs4all.nl 6878 [2001:888:2000:d::a6]:34962
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:22416

Show key headers only | View raw


On 3/31/2012 2:22 AM, Yingjie Lan wrote:
> Hi all,
>
> I'd really like to share this idea of string interpolation for formatting.
> Let's start with some code:
>
>  >>> name = "Shrek"
>  >>> print( "Hi, $name$!")
> Hi, Shrek!
>  >>> balls = 30
>  >>> print( "We have $balls$ balls.")
> We have 30 balls

You can already do essentially that without adding a special-case string 
formatting method to the general methods we already have.

 >>> balls = 5
 >>> people = 3
 >>> 'The {people} people have {balls} balls.'.format(**locals())
'The 3 people have 5 balls.'

-- 
Terry Jan Reedy

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


Thread

Re: string interpolation for python Terry Reedy <tjreedy@udel.edu> - 2012-03-31 06:29 -0400
  Re: string interpolation for python Steve Howell <showell30@yahoo.com> - 2012-03-31 10:51 -0700

csiph-web