Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33820
| 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 | <python-python-list@m.gmane.org> |
| 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 <tjreedy@udel.edu> |
| Subject | Re: Yet another Python textbook |
| Date | Thu, 22 Nov 2012 17:12:42 -0500 |
| References | <CAB89DN0nusHZU32zP5UbTSUH8P7aXJomssBT-Jge7LEhaOtphg@mail.gmail.com> <CALwzid=3b_Gv3XR5iYvo7Pc0ZjXERB60daT9AjVoOG1OAP9vNg@mail.gmail.com> <CAB89DN0M5NzpoLRtcXRtM4Vs4xrOfw0wZq64GkU-DKy=Ei8HJQ@mail.gmail.com> <mailman.34.1353398989.29569.python-list@python.org> <31a82817-8c9b-4dd2-a468-89d8d081fd1b@googlegroups.com> <mailman.96.1353445247.29569.python-list@python.org> <50AD0962.5080002@ncf.ca> <mailman.180.1353536254.29569.python-list@python.org> <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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.214.1353622392.29569.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
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 “formatted” representation, as controlled by
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__
<method '__format__' of 'object' objects>
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
argument, however there is a standard formatting syntax that is used by
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
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
numbers as strings. Collection classes other than str recursively format
their members using str() or repr() until they reach strings, numbers,
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
format one object with two % format specs, it will fail for the same
reason. Try the % equivalent of what failed.
'%-14f%14d' % ((-25.61, 95 ),)
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Yet another Python textbook Chris Angelico <rosuav@gmail.com> - 2012-11-20 19:09 +1100
Re: Yet another Python textbook wxjmfauth@gmail.com - 2012-11-20 06:57 -0800
Re: Yet another Python textbook Chris Angelico <rosuav@gmail.com> - 2012-11-21 08:00 +1100
Re: Yet another Python textbook wxjmfauth@gmail.com - 2012-11-21 06:49 -0800
Re: Yet another Python textbook wxjmfauth@gmail.com - 2012-11-21 06:49 -0800
Re: Yet another Python textbook "Colin J. Williams" <cjw@ncf.ca> - 2012-11-21 12:03 -0500
Re: Yet another Python textbook Chris Angelico <rosuav@gmail.com> - 2012-11-22 09:17 +1100
Re: Yet another Python textbook "Colin J. Williams" <cjw@ncf.ca> - 2012-11-22 07:24 -0500
Re: Yet another Python textbook Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-22 11:27 -0700
Re: Yet another Python textbook "Colin J. Williams" <cjw@ncf.ca> - 2012-11-22 17:41 -0500
Re: Yet another Python textbook Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-23 03:26 +0000
Re: Yet another Python textbook Terry Reedy <tjreedy@udel.edu> - 2012-11-22 17:12 -0500
Re: Yet another Python textbook Dave Angel <d@davea.name> - 2012-11-21 17:58 -0500
Re: Yet another Python textbook Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-21 16:11 -0700
Re: Yet another Python textbook Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-21 23:26 +0000
Re: Yet another Python textbook Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-21 23:32 +0000
Re: Yet another Python textbook Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-21 17:19 -0700
Re: Yet another Python textbook Terry Reedy <tjreedy@udel.edu> - 2012-11-21 23:04 -0500
Re: Yet another Python textbook Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-11-20 21:55 +0000
Re: Yet another Python textbook Chris Angelico <rosuav@gmail.com> - 2012-11-21 09:25 +1100
csiph-web