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: 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: References: From: =?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?= Date: Tue, 21 May 2013 21:06:11 +0200 Subject: Re: PEP 378: Format Specifier for Thousands Separator To: Carlos Nepomuceno Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Tue, May 21, 2013 at 8:49 PM, Carlos Nepomuceno 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 =3D 2) > So, the question is: Where would I change the CPython 2.7.5 source code t= o enable '%' (BINARY_MODULO) to format using the thousands separator like s= tr.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=E2=80=99t do that. Instead, > >>> sys.stdout.write('Number =3D %s\n' % '{:,.0f}'.format(x)) > Number =3D 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=E2=80=99t just a sledgehammer, it=E2=80=99s something worse. Just do that: >>> sys.stdout.write('Number =3D {:,.0f}\n'.format(x)) Much more peaceful. You can also do a print, like everyone sane would. Where did you learn Python from? =E2=80=9CPython Worst Practice for Dummies=E2=80=9D? -- Kwpolska | GPG KEY: 5EAAEA16 stop html mail | always bottom-post http://asciiribbon.org | http://caliburn.nl/topposting.html