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

Guido van Rossum guido at python.org
Tue Mar 17 15:17:10 CET 2009


On Tue, Mar 17, 2009 at 6:24 AM, Eric Smith <eric at trueblade.com> wrote:
> Mark Dickinson wrote:
>>
>> On Tue, Mar 17, 2009 at 11:15 AM, Eric Smith <eric at trueblade.com> wrote:
>>>
>>> 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).
>>
>> But they *are* inserted by locale.format, and
>> presumably no-one has complained about that either. :-)
>>
>>>>> format('%014f', 123.456, grouping=1)
>>
>> '0,000,123.456000'
>>
>> It appears that locale.format adds the thousand separators after
>> the fact, so the issue with the leading comma doesn't come up.
>> That also means that the relationship between the field width (14
>> in this case) and the string length (16) is somewhat obscured.
>
> Ick. Presumably you specified a width because that's how wide you wanted the
> output to be!
>
> I still like leaving the commas out of leading zeros.

Ick, the discrepancy between the behavior of locale.format() and PEP
378 is unfortunate. I agree that the given width should include the
commas, but I strongly feel that leading zeros should be comma-fied
just like everything else.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list