[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 17:36:10 CET 2009


On Tue, Mar 17, 2009 at 8:12 AM, Mark Dickinson <dickinsm at gmail.com> wrote:
> On Tue, Mar 17, 2009 at 2:58 PM, Eric Smith <eric at trueblade.com> wrote:
>> And what happens when the comma would be the first character?
>>
>> ,012,345
>> 0012,345
>>
>> or something else?
>
> Options are:
>
> (A) ",012,345"
> (B) "0012,345"

Neither (A) nor (B) is acceptable.

> (C) " 012,345"
> (D) "0,012,345"
> (E) write-in option here
>
> I vote for (D):  it's one character too large, but the given precision
> is only supposed to be a minimum anyway.  We already end up
> with a length-9 string when formatting 1234567.
>
> (D) is the minimum width string that:
>  doesn't look weird (like (A) and (B)),
>  has length at least 8, and
>  is still in the right basic format
>
> (C) would be my second choice, but I find the extra space padding
> to be somewhat arbitrary (why a space? why not some other
> padding character?)

It's tough to choose between (C) and (D). I guess we'll have to look
at use cases for leading zeros. I can think of two use cases for
leading zeros are: (1) To avoid font-width issues -- many
variable-width fonts are designed so that all digits have the same
width, but their (default) space is much narrower. (2) To avoid fraud
when printing certain documents -- it's easier to insert a '1' in
front of a small number than to change a '0' into something else.

Since both use cases are trying to avoid spaces, I think (D) is the winner here.

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



More information about the Python-ideas mailing list