Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:verizon.net': 0.07; 'terry': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'valueerror:': 0.09; '2.7': 0.13; '-tkc': 0.16; '2.6,': 0.16; 'benjamin': 0.16; 'reedy': 0.16; 'subject:vs.': 0.16; '{}"': 0.16; 'syntax': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'jan': 0.19; '(most': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'versions': 0.23; 'debian': 0.23; 'string': 0.24; 'traceback': 0.24; 'pm,': 0.29; 'skip:p 30': 0.29; 'quite': 0.32; 'earlier': 0.32; 'header :User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'to:addr :python-list': 0.34; 'last):': 0.34; 'file': 0.36; 'class.': 0.37; 'received:org': 0.38; 'some': 0.38; 'to:addr:python.org': 0.40; 'below': 0.63 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: .format vs. % Date: Sat, 31 Dec 2011 16:09:09 -0500 References: <5642862.375.1325355574622.JavaMail.geo-discussion-forums@vbbhx10> <3779937.289.1325357048110.JavaMail.geo-discussion-forums@vbtv37> <4EFF615A.1050008@tim.thechases.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: <4EFF615A.1050008@tim.thechases.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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325365772 news.xs4all.nl 6933 [2001:888:2000:d::a6]:54257 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18280 On 12/31/2011 2:24 PM, Tim Chase wrote: > On 12/31/11 12:57, Benjamin Kaplan wrote: >> format is a method of the string class. You store the string the same way >> you would any other. >> >> formatter = "Hello, {}" >> print(formatter.format("world")) > > Just to note that this syntax doesn't quite work in some earlier > versions (tested below in 2.6, which came stock in Debian Stable) Autonumbering of {} was introduced, at my suggestion, in 3.1 and included with 2.7 (I presume). > > >>> formatter = "Hello, {}" > >>> print(formatter.format("world")) > Traceback (most recent call last): > File "", line 1, in > ValueError: zero length field name in format > > > It needs to be spelled "{0}" > > -tkc > > -- Terry Jan Reedy