Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45706
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <carlosnepomuceno@outlook.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.008 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'output': 0.05; 'subject:PEP': 0.07; 'additionally': 0.09; 'literal': 0.09; 'pep': 0.09; 'used.': 0.09; 'python': 0.11; 'language.': 0.14; '10000000': 0.16; '7.98': 0.16; 'formatting.': 0.16; 'specifier': 0.16; 'str.format()': 0.16; 'appropriate': 0.16; 'language': 0.16; 'wed,': 0.18; 'code,': 0.22; '+0000': 0.22; 'issue.': 0.22; 'to:name:python-list@python.org': 0.22; 'integer': 0.24; 'received:65.55.116': 0.24; 'source': 0.25; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'skip:- 40': 0.29; '[1]': 0.29; 'url:mailman': 0.30; 'code': 0.31; 'decimal': 0.31; 'fighting': 0.31; 'steven': 0.31; 'another': 0.32; 'url:python': 0.33; 'running': 0.33; 'call.': 0.33; 'raw': 0.33; 'date:': 0.34; 'maybe': 0.34; 'something': 0.35; 'but': 0.35; 'url:listinfo': 0.36; 'shows': 0.36; 'url:org': 0.36; 'so,': 0.37; 'email addr:python.org': 0.37; 'performance': 0.37; 'to:addr :python-list': 0.38; 'fact': 0.38; 'little': 0.38; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'even': 0.60; 'above,': 0.60; 'full': 0.61; 'simple': 0.61; 'times': 0.62; 're:': 0.63; 'more': 0.64; 'different': 0.65; 'email name:python- list': 0.65; 'rendering': 0.68; '10%': 0.74; 'all!': 0.84; 'alternative.': 0.84; 'gain,': 0.84; 'fight': 0.97; '2013': 0.98 |
| X-TMN | [v0rIGP/D3mQtlHL29IOTGelZAdPfgKME] |
| X-Originating-Email | [carlosnepomuceno@outlook.com] |
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Subject | RE: PEP 378: Format Specifier for Thousands Separator |
| Date | Wed, 22 May 2013 06:38:45 +0300 |
| Importance | Normal |
| In-Reply-To | <519c36c6$0$6599$c3e8da3$5496439d@news.astraweb.com> |
| References | <knghok$3bd$1@ger.gmane.org> <519c36c6$0$6599$c3e8da3$5496439d@news.astraweb.com> |
| Content-Type | text/plain; charset="iso-8859-1" |
| Content-Transfer-Encoding | quoted-printable |
| MIME-Version | 1.0 |
| X-OriginalArrivalTime | 22 May 2013 03:38:45.0471 (UTC) FILETIME=[DCCEAEF0:01CE569D] |
| 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.1951.1369193993.3114.python-list@python.org> (permalink) |
| Lines | 59 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1369193993 news.xs4all.nl 15964 [2001:888:2000:d::a6]:50707 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:45706 |
Show key headers only | View raw
----------------------------------------
> From: steve+comp.lang.python@pearwood.info
> Subject: Re: PEP 378: Format Specifier for Thousands Separator
> Date: Wed, 22 May 2013 03:08:54 +0000
> To: python-list@python.org
[...]
>> So, the only alternative to have "'%,d' % x" rendering the thousands
>> separator output would a C source code modification?
>
> That's one alternative. But the language you would be then running will
> no longer be Python.
>
> Another alternative would be to write a pre-processor that parses your
> Python source code, extracts any reference to the above, and replaces it
> with a call to the appropriate format call. But not only is that a lot of
> work for very little gain, but it's also more or less impossible to do in
> full generality. And again, what you are running will be something
> different than Python, it will be Python plus a pre-processor.
>
>
> Don't fight the language. You will lose.
Not fighting the language. In fact it's not even a language issue.
All I need is a standard library[1] improvement: "%,d"! That's all!
Just to put in perspective the performance difference of str.__mod__() and str.format():
C:\Python27>python -m timeit -cv -n10000000 "'%d'%12345"
raw times: 0.386 0.38 0.373
10000000 loops, best of 3: 0.0373 usec per loop
C:\Python27>python -m timeit -cv -n10000000 "'{:d}'.format(12345)"
raw times: 7.91 7.89 7.98
10000000 loops, best of 3: 0.789 usec per loop
C:\Python27>python -m timeit -cv -n10000000 "'{:,d}'.format(12345)"
raw times: 8.7 8.67 8.78
10000000 loops, best of 3: 0.867 usec per loop
That shows str.format() is 20 times slower than str.__mod__() for a simple decimal integer literal formatting.
And it's additionally 10% slower if the thousands separator format specifier (',') is used.
[1] I think that translates to Python source code in 'Objects/stringobject.c' and maybe 'Objects/unicodeobject.c'
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
RE: PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-21 23:22 +0300
Re: PEP 378: Format Specifier for Thousands Separator Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-22 02:42 +0000
RE: PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-22 05:56 +0300
Re: PEP 378: Format Specifier for Thousands Separator Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-22 03:08 +0000
RE: PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-22 06:38 +0300
Re: PEP 378: Format Specifier for Thousands Separator 88888 Dihedral <dihedral88888@gmail.com> - 2013-05-22 00:14 -0700
Re: PEP 378: Format Specifier for Thousands Separator Ned Batchelder <ned@nedbatchelder.com> - 2013-05-22 07:25 -0400
RE: PEP 378: Format Specifier for Thousands Separator Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-22 14:52 +0300
csiph-web