Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!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.042 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; '21,': 0.07; 'brasil': 0.07; 'python3': 0.07; 'subject:PEP': 0.07; 'integers': 0.09; 'python': 0.11; '3.1.3': 0.16; 'alguns': 0.16; 'possible?': 0.16; 'specifier': 0.16; 'unsigned': 0.16; 'wrote:': 0.18; '>>>': 0.22; '>>>': 0.24; 'integer': 0.24; '>': 0.26; '2010,': 0.27; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; 'am,': 0.29; 'received:209.85.217': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'twitter:': 0.31; 'skip:= 40': 0.31; 'url:python': 0.33; 'blog:': 0.33; "i'd": 0.34; 'received:209.85': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'received:209': 0.37; 'skip:& 10': 0.38; 'nov': 0.38; 'to:addr :python-list': 0.38; 'skip:& 20': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'skip:n 10': 0.64; 'more': 0.64; 'url:facebook': 0.67; 'url:gl': 0.72; 'url:goo': 0.75; 'article': 0.77; 'dar': 0.84; 'meu': 0.84; 'carlos': 0.91; 'facebook:': 0.91; '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 :content-type; bh=XgZGHqw8X2TC1LICxNXIl9T/HZuj3QfcKvHoRZmj1kY=; b=dZHvRJ0JKjGeRL/Orb9WQSEEJ4qBFdr0g2OvSP3zGM3Dmbq9ghvo8+dOkucftj+UMq wLqTQpa03lARVUa2DqQX/MUGiwD+5EicDpi4aWVe1U49p5fpHgkNi1nS1XrdRA64Aygs xO6K9+e3/Db7ptyWfkzsj275pneMVPge4WHCwfRHW3NnGTvjverNZz5oWocd19b3hoXY uy5AJP1QE1lj3pGzHEcanDB7e4A3J/aRikikpCxhf1TJIEmicj8TY5e3j6wScHi4rCdB 5eISo/6wcB3Ufeu6F/A6Rghdypfhd2Sp1oGaDDzqOklxc06nNgs9YvPq5/tMLXSPGgMt Dciw== X-Received: by 10.112.19.133 with SMTP id f5mr1359158lbe.98.1369137833727; Tue, 21 May 2013 05:03:53 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Alysson Bruno Date: Tue, 21 May 2013 09:03:13 -0300 Subject: Re: PEP 378: Format Specifier for Thousands Separator To: python-list@python.org Content-Type: multipart/alternative; boundary=14dae93d8c863a5e2804dd393e3a 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: 146 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369137842 news.xs4all.nl 16008 [2001:888:2000:d::a6]:43709 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45664 --14dae93d8c863a5e2804dd393e3a Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable This work in 3.1+: $ python3 Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> one_number =3D 1234567 >>> print('number=3D{:,}'.format(one_number)) number=3D1,234,567 >>> paz e amor (love and peace), Alysson Bruno =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Palmas(TO) Brasil Blog: http://abruno.com Twitter: http://twitter.com/alyssonbruno Facebook: http://www.facebook.com/ProfessorAlyssonBruno =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D *Meu alterego Escritor:* Leia alguns contos que escrevo, n=C3=A3o esque=C3=A7a de me dar sua opini= =C3=A3o: http://goo.gl/Wjn4p =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D On Tue, May 21, 2013 at 2:44 AM, Ned Deily wrote: > In article , > Carlos Nepomuceno wrote: > > Is there a way to format integers with thousands separator (digit > grouping) > > like the format specifier of str.format()?> > > I'm currently using the following:> > > >>> 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!> > > I'd like to have something like: > > sys.stdout.write('Number =3D %,u\n' % x) > > Is that possible? How can I do it if not already available? > > For Python 3.2+ or 2.7, why not just: > > >>> print('Number =3D {:,}'.format(x)) > Number =3D 12,345 > > -- > Ned Deily, > nad@acm.org > > -- > http://mail.python.org/mailman/listinfo/python-list > --14dae93d8c863a5e2804dd393e3a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
This work in 3.1+:

$ python3
Python 3.1.3 (r3= 13:86834, Nov 28 2010, 11:28:10)
[GCC 4.4.5] on linux2
Type "help", "copyright", &quo= t;credits" or "license" for more information.
>>>= ; one_number =3D 1234567
>>> print('number=3D{:,}'.form= at(one_number))
number=3D1,234,567
>>>

paz e a= mor (love and peace),

Alysson Bruno
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D
Palmas(TO)
Brasil

Blog:=C2=A0http://abruno.com

Facebook:=C2=A0http://www.facebook.com/ProfessorAlyssonBruno

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Meu alterego Escritor:

Leia alg= uns contos que escrevo, n=C3=A3o esque=C3=A7a de me dar sua opini=C3=A3o:= =C2=A0http://goo.gl/Wjn4p=

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


On Tue, May 21, 2013 at 2:44 AM, Ned Dei= ly <n= ad@acm.org> wrote:
In article <BLU176-W10190CB892A0414C988A05D7A80@phx.gbl>,
=C2=A0Carlos Nepomuceno <carlosnepomuceno@outlook.com> wrote:
> Is there a way to format integers with thousands separator (digit grou= ping)
> like the format specifier of str.format()?>
> I'm currently using the following:>
> >>> 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!>
> I'd like to have something like:
> sys.stdout.write('Number =3D %,u\n' % x)
> Is that possible? How can I do it if not already available?

For Python 3.2+ or 2.7, why not just:

>>> print('Number =3D {:,}'.format(x))
Number =3D 12,345

--
=C2=A0Ned Deily,
=C2=A0nad@acm.org

--
http://mail.python.org/mailman/listinfo/python-list

--14dae93d8c863a5e2804dd393e3a--