Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'instance': 0.05; 'suppose': 0.05; 'refers': 0.07; 'terry': 0.07; 'wrapper': 0.07; '*and*': 0.09; '>>>>': 0.09; 'argument,': 0.09; 'etc).': 0.09; 'float.': 0.09; 'rounding': 0.09; 'statement.': 0.09; 'subject:string': 0.09; 'thrown': 0.09; 'pm,': 0.10; '>>>': 0.12; 'am,': 0.14; 'wrote:': 0.14; '(before': 0.16; '-tkc': 0.16; 'appropriate)': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'iterator': 0.16; 'message-id:@tim.thechases.com': 0.16; 'partitioning': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'reedy': 0.16; 'spec,': 0.16; 'subject:formatting': 0.16; 'subject:syntax': 0.16; 'url:format': 0.16; '{0}': 0.16; 'preference': 0.16; 'subject:was': 0.16; 'possibly': 0.16; 'cc:addr:python-list': 0.17; 'meant': 0.18; 'guess': 0.19; 'header :In-Reply-To:1': 0.21; 'seems': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'currency': 0.23; 'optional': 0.23; 'vs.': 0.23; 'preferred': 0.26; 'statement': 0.26; 'testing': 0.27; "i'm": 0.27; '(even': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.30; '"in': 0.30; 'chase': 0.30; 'decimal': 0.30; 'preceding': 0.30; 'it.': 0.31; 'url:library': 0.31; 'does': 0.33; 'things': 0.33; '...': 0.34; 'characters': 0.34; 'showing': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'skip:" 10': 0.35; 'source,': 0.35; 'subject:What': 0.35; 'symbol': 0.35; 'wishes,': 0.35; 'test': 0.35; 'subject:new': 0.37; 'url:docs': 0.37; 'case': 0.37; 'url:python': 0.38; 'url:org': 0.38; 'but': 0.38; 'docs': 0.38; 'linked': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'should': 0.39; 'unless': 0.39; 'either': 0.39; 'add': 0.39; 'error.': 0.40; 'feature': 0.40; 'format': 0.40; 'your': 0.60; 'according': 0.63; 'link': 0.64; 'saw': 0.64; 'direction.': 0.65; 'became': 0.67; 'subject:this': 0.76; 'money': 0.78; 'gotcha': 0.84; 'huh?': 0.84; 'i18n': 0.84; 'warning.': 0.84; 'vocal': 0.91 Date: Tue, 21 Jun 2011 18:02:03 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: Terry Reedy Subject: Re: new string-formatting preferred? (was "What is this syntax ?") References: <87pqm8qh7m.fsf@benfinney.id.au> <4DFFE9D5.30300@tim.thechases.com> <4E008179.600@tim.thechases.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: python-list@python.org 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: 63 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308697338 news.xs4all.nl 49041 [::ffff:82.94.164.166]:45336 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8141 On 06/21/2011 05:19 PM, Terry Reedy wrote: > On 6/21/2011 7:33 AM, Tim Chase wrote: >>>>> >>>> >>>> Is there a good link to a thread-archive on when/why/how .format(...) >>>> became "preferred to the % formatting"? >>> >>> That is a controversial statement. >> >> I'm not sure whether you're "controversial" refers to >> >> - the documentation at that link, > > I meant the preceding statement (derived from the linked source, but > that is not important) that .format is preferred to %. I guess then with all the contention, having such a vocal preference in the docs (even if tempered by "in new code") seems to unnecessarily polarize when I find myself very "meh" in either direction. >>> multi_warn = '''\ >>> Warning: testing multiple {0}s against an iterator will only test >>> the first {0} unless the iterator is reiterable; most are not.'''.format >>> ... >>> print(multiwarn('function')) >>> ... >>> print(multiwarn('iterator')) >> >> Does the gotcha of a non-restarting iterator > > Huh? What iterator? Your string-body text warns about behavior regarding iterators. I was thrown by your warning. >> The other new feature I saw was the use of __format__() > > Suppose one had a Money class with currency and decimal amount fields. > .__str__ can add a currency symbol (before or after as appropriate) but > has to use a standard format for the amount field. .__float__ can be > post-processed according to a %...f spec, but cannot include a currency > symbol. Money.__format__(self,spec) can format the amount at it wishes, > including its rounding rules, *and* add a currency symbol. A Money class was one of the first things I thought of, but figured that would be better relegated to an i18n wrapper if you wanted it. Such a wrapper would handle currency-symbol choice & positioning positioning (before vs. after; relation to the +/-; optional characters for thousands-separators and decimal separators; and partitioning at thousands-or-other-multiples, etc). > Or suppose one has a multi-precision float. %80.40f will require an mpf > instance to appoximate itself as a float, possibly with error. > mpg.__format__ should be able to do better. This case makes a better argument, showing me some new value added by __format__(). -tkc