[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 22:13:14 CET 2009


Eric Smith wrote:
> Mark Dickinson wrote:
>> 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')
> 'en_US.UTF8'
>  >>> format(12345, '010n')
> '000012,345'
>  >>> format(12345, '09n')
> '00012,345'
>  >>> format(12345, '08n')
> '0012,345'
>  >>> format(12345, '07n')
> '012,345'
>  >>> format(12345, '06n')
> '12,345'

I think this is a bug that should be fixed in the same way we implement 
it for PEP 378.

It's more complex for 'n', because you might have funny groupings (like 
very 3, then 2). But I hope our solution for PEP 378 will generalize to 
this case, too.

Eric.



More information about the Python-ideas mailing list