[Python-ideas] Rough draft: Proposed format specifier for a thousands separator (discussion moved from python-dev)

Eric Smith eric at trueblade.com
Tue Mar 17 12:15:13 CET 2009

Mark Dickinson wrote:
> On Tue, Mar 17, 2009 at 3:14 AM, Guido van Rossum <guido at python.org> wrote:
>> On Mon, Mar 16, 2009 at 7:33 PM, Raymond Hettinger <python at rcn.com> wrote:
>>> Mark PEP 378 as accepted with Nick's original comma-only version?
>> OK, done. Looking forward to a swift implementation!
> I'll implement this for Decimal;  it shouldn't take long.
> One question from the PEP, which I've been too slow to read until
> this morning:  should commas appear in the zero-filled part of a
> number?  That is, should format(1234, "09,d") give '00001,234'
> or '0,001,234'?  The PEP specifies that format(1234, "08,d")
> should give '0001,234', but that's something of a special case:
> ',001,234' isn't really a viable alternative.

Hmm. No good answers here. I'd vote for not putting the commas in the 
leading zeros.  I don't think anyone would ever actually use this 
combination, and putting commas there complicates things due to the 
special case with the first digit.

Plus, they're not inserted by the 'n' formatter, and no one has 
complained (which might mean no one's using it, of course).

In 2.6:

 >>> import locale
 >>> locale.setlocale(locale.LC_ALL, 'en_US.UTF8')
 >>> format(12345, '010n')
 >>> format(12345, '09n')
 >>> format(12345, '08n')
 >>> format(12345, '07n')
 >>> format(12345, '06n')

More information about the Python-ideas mailing list