Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45664
| References | <BLU176-W10190CB892A0414C988A05D7A80@phx.gbl> <nad-F52CE7.22440720052013@news.gmane.org> |
|---|---|
| From | Alysson Bruno <alyssonbruno@gmail.com> |
| Date | 2013-05-21 09:03 -0300 |
| Subject | Re: PEP 378: Format Specifier for Thousands Separator |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1921.1369137842.3114.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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 = 1234567
>>> print('number={:,}'.format(one_number))
number=1,234,567
>>>
paz e amor (love and peace),
Alysson Bruno
===============================================
Palmas(TO)
Brasil
Blog: http://abruno.com
Twitter: http://twitter.com/alyssonbruno
Facebook: http://www.facebook.com/ProfessorAlyssonBruno
=================================================================
*Meu alterego Escritor:*
Leia alguns contos que escrevo, não esqueça de me dar sua opinião:
http://goo.gl/Wjn4p <http://goo.gl/AXv1g>
=================================================================
On Tue, May 21, 2013 at 2:44 AM, Ned Deily <nad@acm.org> wrote:
> In article <BLU176-W10190CB892A0414C988A05D7A80@phx.gbl>,
> Carlos Nepomuceno <carlosnepomuceno@outlook.com> 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 = %s\n' % '{:,.0f}'.format(x))
> > Number = 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 = %,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 = {:,}'.format(x))
> Number = 12,345
>
> --
> Ned Deily,
> nad@acm.org
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: PEP 378: Format Specifier for Thousands Separator Alysson Bruno <alyssonbruno@gmail.com> - 2013-05-21 09:03 -0300
csiph-web