Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!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; 'that?': 0.05; '*not*': 0.07; 'binary': 0.07; 'subject:PEP': 0.07; 'string': 0.09; 'arguments': 0.09; 'converted': 0.09; 'formatting': 0.09; 'function,': 0.09; 'pretend': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'argument,': 0.16; 'formatted': 0.16; 'itself,': 0.16; 'operation.': 0.16; 'operator.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'tuple': 0.16; 'tuple.': 0.16; 'typeerror:': 0.16; "why's": 0.16; 'wrote:': 0.18; '>>>': 0.22; 'hack': 0.22; 'header:User-Agent:1': 0.23; '(by': 0.24; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; '"",': 0.31; 'file': 0.32; 'another': 0.32; '(most': 0.33; 'problem': 0.35; 'represent': 0.38; 'handle': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'dave': 0.60; 'received:173': 0.61; 'first': 0.61; 'making': 0.63; 'design.': 0.68; 'honest': 0.78; "'2'": 0.84; 'received:fios.verizon.net': 0.84; 'angel': 0.91; 'carlos': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Jan Reedy Subject: Re: PEP 378: Format Specifier for Thousands Separator Date: Thu, 23 May 2013 16:19:33 -0400 References: , , , , , , , , , , , , , , <519c348a$0$6599$c3e8da3$5496439d@news.astraweb.com>, , <519C3D99.5040107@gmail.com>, , , , <519cdcff$0$6599$c3e8da3$5496439d@news.astraweb.com>, , , , <87eaaf24-df6a-4f6b-b873-16ca96c12e24@b2g2000yqe.googlegroups.com>, , <519E6327.8070204@davea.name> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 In-Reply-To: <519E6327.8070204@davea.name> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369341281 news.xs4all.nl 15892 [2001:888:2000:d::a6]:34361 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45841 On 5/23/2013 2:42 PM, Dave Angel wrote: > On 05/23/2013 11:26 AM, Carlos Nepomuceno wrote: > >>>>>> eggs(a,f) >>> Traceback (most recent call last): >>> File "", line 1, in >>> eggs(a,f) >>> File "", line 1, in eggs >>> def eggs(spam, ham): return spam % ham >>> TypeError: not all arguments converted during string formatting >>>>>> '%s'%(5%3) >>> '2' >> >> So % doesn't handle tuples! Why's that? Is it intentional (by design)? >> > > It's a conflict in the design. A tuple is used to supply multiple > arguments to the % operator. So if you want to have a tuple as the > first argument, you need to enclose it in another tuple. The problem is that interpolating 1 to many items into a string is *not* a binary operation. The needed hack to pretend that it is, using a tuple to represent multiple items rather than just itself, was one of the reasons for making string formatting a honest function, where multiple items to be formatted are passed as multiple arguments.