Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.125 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.78; '*S*': 0.03; 'subject:number': 0.09; '-john': 0.16; 'to:addr:web.de': 0.16; 'wrote:': 0.17; 'import': 0.21; 'to:2**1': 0.23; 'least': 0.25; 'header:User-Agent:1': 0.26; 'regular': 0.27; 'to:addr:python-list': 0.33; 'subject:?': 0.35; 'option': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'otten': 0.84; 'received:167': 0.84; 'employ': 0.95 Date: Thu, 07 Mar 2013 14:06:03 -0500 From: John Posner Subject: Re: Insert comma in number? In-reply-to: To: python-list@python.org, Peter Otten <__peter__@web.de> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7BIT X-Enigmail-Version: 1.5.1 References: User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130215 Thunderbird/17.0.3 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: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362684983 news.xs4all.nl 6867 [2001:888:2000:d::a6]:51075 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40813 Peter Otten wrote: > Last not least there's the option to employ locale-aware formatting: Not quite last ... there's the mind-bending regular expression route: import re re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", "12345678") # 12,345,678 re.sub(r"(?<=\d)(?=(\d\d\d)+$)", ",", "-54321") # -54,321 -John