Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!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; 'example:': 0.03; 'syntax': 0.03; 'subject:Python': 0.05; 'say,': 0.05; 'arguments': 0.07; 'formatting': 0.07; 'strings.': 0.07; 'args,': 0.09; 'argument,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spec': 0.09; 'terry': 0.09; 'types:': 0.09; '(the': 0.15; 'value.': 0.15; 'failed.': 0.16; 'format_spec': 0.16; 'formatting.': 0.16; 'reason.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'repr()': 0.16; 'skip:) 30': 0.16; 'str()': 0.16; 'string': 0.17; 'wrote:': 0.17; 'jan': 0.18; '>>>': 0.18; 'skip:p 30': 0.20; 'equivalent': 0.20; '(b)': 0.22; 'controlled': 0.22; 'latter': 0.22; 'seems': 0.23; 'second': 0.24; 'pass': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'am,': 0.27; 'header:X-Complaints-To:1': 0.28; 'methods.': 0.29; 'now?': 0.29; 'str': 0.29; 'strings,': 0.29; 'convert': 0.29; '"the': 0.29; 'class': 0.29; 'classes': 0.30; "skip:' 10": 0.30; '(a)': 0.33; 'instances': 0.33; 'to:addr:python-list': 0.33; '(c)': 0.33; 'built-in': 0.35; 'fail': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'itself': 0.37; 'one,': 0.37; 'two': 0.37; 'passed': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'notice': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'link': 0.60; 'most': 0.61; 'therefore': 0.65; '8bit%:40': 0.65; 'skip:\xe2 10': 0.66; 'nonsense.': 0.84; 'received:fios.verizon.net': 0.84; 'specs.': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Yet another Python textbook Date: Thu, 22 Nov 2012 17:12:42 -0500 References: <31a82817-8c9b-4dd2-a468-89d8d081fd1b@googlegroups.com> <50AD0962.5080002@ncf.ca> <50AE1986.2080605@ncf.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable 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:16.0) Gecko/20121026 Thunderbird/16.0.2 In-Reply-To: <50AE1986.2080605@ncf.ca> 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: 70 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1353622392 news.xs4all.nl 6985 [2001:888:2000:d::a6]:59349 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33820 On 11/22/2012 7:24 AM, Colin J. Williams wrote: > From my reading of the docs, it seems to me that the three following > should be equivalent: We read differently... > > (a) formattingStr.format(values) Where 'values' is multiple arguments > with > (b) format(values, formattingStr) "format(value[, format_spec]) Convert a value to a =E2=80=9Cformatted=E2=80=9D representation, as contr= olled by=20 format_spec." I notice that you did not pass multiple args, but indeed just one. A 'format_spec' is only part of a {} formatting field. > or > (c) tupleOfValues.__format__(formattingStr >>> tuple.__format__ Which of to say, not specific to tuples. > Example: > print('{:-^14f}{:^14d}'.format(-25.61, 95 )) > print(format((-25.61, 95), '{:-^14f}{:^14d}')) "The interpretation of format_spec will depend on the type of the value=20 argument, however there is a standard formatting syntax that is used by=20 most built-in types: Format Specification Mini-Language." (The latter is = link to the FSML. '-^14f' and '^14d' are format_specs. '{:-^14f}{:^14d}' is a format string that includes two fields with=20 format specs. It is not a format spec in itself and is therefore invalid = by the doc. > (-25.61, 95 ).__format__('{:-^14f}{:^14d}') > > The second fails, perhaps because values can only be a single value. You only passed one, but you did not pass a format spec and indeed there = is none for tuples. As delivered, format specs only format strings and=20 numbers as strings. Collection classes other than str recursively format = their members using str() or repr() until they reach strings, numbers,=20 or customs class instances with custom .__format__ methods. > Should we retreat to %-formatting for now? Nonsense. The issues above are the same for % formatting. If you try to=20 format one object with two % format specs, it will fail for the same=20 reason. Try the % equivalent of what failed. '%-14f%14d' % ((-25.61, 95 ),) --=20 Terry Jan Reedy