Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python': 0.08; 'locale': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:peps': 0.09; 'comma': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'from:addr:web.de': 0.23; 'pep': 0.23; 'url:dev': 0.23; 'do,': 0.25; 'import': 0.27; "skip:' 10": 0.29; 'pm,': 0.29; 'ran': 0.30; 'subject:number': 0.30; 'chris': 0.30; 'actually': 0.31; 'skip:l 30': 0.32; 'thu,': 0.32; 'header:X-Complaints-To:1': 0.34; 'latter': 0.34; 'to:addr:python-list': 0.35; 'skip:" 20': 0.35; 'url:python': 0.35; 'received:org': 0.36; 'skip:" 10': 0.37; 'subject:with': 0.37; 'should': 0.38; 'url:org': 0.39; 'to:addr:python.org': 0.40; '12:39': 0.84; '378': 0.84; 'otten': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Formate a number with commas Date: Thu, 09 Feb 2012 22:16:03 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084adf6.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 1328822181 news.xs4all.nl 6864 [2001:888:2000:d::a6]:60100 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20112 Chris Rebert wrote: > On Thu, Feb 9, 2012 at 12:39 PM, Peter Otten <__peter__@web.de> wrote: >>>>> import locale >>>>> locale.setlocale(locale.LC_ALL, "") >> 'de_DE.UTF-8' >>>>> "{:n}".format(1234) # locale-aware >> '1.234' >>>>> "{:,d}".format(1234) # always a comma >> '1,234' > > The latter requires Python 3.1+ and is courtesy PEP 378 > (http://www.python.org/dev/peps/pep-0378/ ). I actually ran the above session in 2.7, so that should do, too. http://docs.python.org/whatsnew/2.7.html#pep-378-format-specifier-for- thousands-separator