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: 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 Subject: Re: string interpolation for python Date: Sat, 31 Mar 2012 06:29:11 -0400 References: <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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