Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45681

Re: PEP 378: Format Specifier for Thousands Separator

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!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <kwpolska@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'cpython': 0.05; '21,': 0.07; 'made.': 0.07; 'skip:` 10': 0.07; 'subject:PEP': 0.07; 'modulo': 0.09; 'performs': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'does,': 0.16; 'gpg': 0.16; 'luck,': 0.16; 'sane': 0.16; 'skip:> 20': 0.16; 'str.format()': 0.16; 'unsigned': 0.16; 'worse.': 0.16; 'worst': 0.16; 'wrote:': 0.18; '(where': 0.19; '>>>': 0.22; 'python?': 0.22; 'cc:addr:python.org': 0.22; 'instead.': 0.24; 'integer': 0.24; 'skip:{ 20': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'source': 0.25; 'header:In-Reply-To:1': 0.27; 'patch': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'that.': 0.31; 'division': 0.31; 'this.': 0.32; 'everyone': 0.33; "i'd": 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'two': 0.37; 'thank': 0.38; 'pm,': 0.38; 'even': 0.60; 'new': 0.61; 'from:charset:utf-8': 0.61; 'name': 0.63; 'real': 0.63; 'such': 0.63; 'more': 0.64; 'as:': 0.81; 'it\xe2\x80\x99s': 0.84; 'carlos': 0.91; 'don\xe2\x80\x99t': 0.91; 'tough': 0.93; 'url:tk': 0.95; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=V3ExEoYubj3d31UVLaFljMpsnR619CEJP2gvU5nEnt4=; b=Ax5Kfjq/Cwc5vRmYfK/gVCyNEG/re6ykAjdYWyvAmk4Wk06oDXCy8gH0zDc34U2j7T b95N/+lwvsbLYVa1Wj688SBEWJ3zt+UdPwHkb0mEncmlq0MkfN7KMoZfJTSBI8+WkGpE kaY+vDKeeFA8VZg+t1yBxO/MPxt7LeJ747O/JSp+E1JUIAjTAAM2VAabIyDIg2WCUMci D8S5pmPAynlgxd9GND4FiW6eNAtXVix8CumhXbQKK+CPoTyqOuPQGRZMHyGATxpct5RL Ucxqu+VAIRFSkX+5250IW8ueOeDelr5guzqsvmOmAWxoQUeppn17pF1qu8LxNsduxDpN cURA==
X-Received by 10.50.3.67 with SMTP id a3mr2237480iga.88.1369163191328; Tue, 21 May 2013 12:06:31 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <BLU176-W9FF52BDCE42DAF40E6AC7D7A80@phx.gbl>
References <BLU176-W10190CB892A0414C988A05D7A80@phx.gbl> <nad-F52CE7.22440720052013@news.gmane.org> <CADUW+M=Y7b=4ZEENVzx4p6YpVD8T0eG=qz7sz8+iEow-5-o+jQ@mail.gmail.com> <BLU176-W9FF52BDCE42DAF40E6AC7D7A80@phx.gbl>
From Chris “Kwpolska” Warrick <kwpolska@gmail.com>
Date Tue, 21 May 2013 21:06:11 +0200
Subject Re: PEP 378: Format Specifier for Thousands Separator
To Carlos Nepomuceno <carlosnepomuceno@outlook.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Cc "python-list@python.org" <python-list@python.org>
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.1931.1369163194.3114.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369163194 news.xs4all.nl 15907 [2001:888:2000:d::a6]:40208
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45681

Show key headers only | View raw


On Tue, May 21, 2013 at 8:49 PM, Carlos Nepomuceno
<carlosnepomuceno@outlook.com> wrote:
> Thank you, but let me rephrase it. I'm already using str.format() but I'd like to use '%' (BINARY_MODULO) operator instead.

There is no real reason to do this.  `str.format()` is the new shiny
thing you should be using all the time.  Also, '%' is BINARY_MODULO
(where did you even get that name from?) if and only if you have two
numbers, and it performs the modulo division (eg. 27 % 5 = 2)

> So, the question is: Where would I change the CPython 2.7.5 source code to enable '%' (BINARY_MODULO) to format using the thousands separator like str.format() does, such as:
>
>>>>sys.stderr.write('%,d\n' % 1234567)
> 1,234,567

This will make your code unportable and useless, depending on one
patch you made.  Please don’t do that.  Instead,

> >>> sys.stdout.write('Number = %s\n' % '{:,.0f}'.format(x))
> Number = 12,345
>
> 'x' is unsigned integer so it's like using a sledgehammer to crack a nut!

In Python?  Tough luck, every int is signed.  And it isn’t just a
sledgehammer, it’s something worse.  Just do that:

>>> sys.stdout.write('Number = {:,.0f}\n'.format(x))

Much more peaceful.

You can also do a print, like everyone sane would.  Where did you
learn Python from?  “Python Worst Practice for Dummies”?

--
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: PEP 378: Format Specifier for Thousands Separator Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-05-21 21:06 +0200

csiph-web