Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45643 > unrolled thread
| Started by | Ned Deily <nad@acm.org> |
|---|---|
| First post | 2013-05-20 22:44 -0700 |
| Last post | 2013-05-20 22:44 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: PEP 378: Format Specifier for Thousands Separator Ned Deily <nad@acm.org> - 2013-05-20 22:44 -0700
| From | Ned Deily <nad@acm.org> |
|---|---|
| Date | 2013-05-20 22:44 -0700 |
| Subject | Re: PEP 378: Format Specifier for Thousands Separator |
| Message-ID | <mailman.1903.1369115068.3114.python-list@python.org> |
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
Back to top | Article view | comp.lang.python
csiph-web