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: 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 Subject: Re: PEP 378: Format Specifier for Thousands Separator Date: Mon, 20 May 2013 22:44:08 -0700 References: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 = %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