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


Groups > comp.lang.python > #45643

Re: PEP 378: Format Specifier for Thousands Separator

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:PEP': 0.07; 'integers': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'possible?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'specifier': 0.16; 'unsigned': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'integer': 0.24; 'header:X-Complaints-To:1': 0.27; "i'm": 0.30; "i'd": 0.34; 'something': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'received:204': 0.75; 'article': 0.77; 'received:204.14': 0.84; 'carlos': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Deily <nad@acm.org>
Subject Re: PEP 378: Format Specifier for Thousands Separator
Date Mon, 20 May 2013 22:44:08 -0700
References <BLU176-W10190CB892A0414C988A05D7A80@phx.gbl>
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 204.14.154.191
User-Agent MT-NewsWatcher/3.5.3b3 (Intel Mac OS X)
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.1903.1369115068.3114.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369115068 news.xs4all.nl 15986 [2001:888:2000:d::a6]:36200
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45643

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: PEP 378: Format Specifier for Thousands Separator Ned Deily <nad@acm.org> - 2013-05-20 22:44 -0700

csiph-web