[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 00:42:10 CET 2009
On Mon, Mar 16, 2009 at 4:25 PM, Raymond Hettinger <python at rcn.com> wrote:
>> Argh! So "8,1f" means "use comma instead of point" wherease "8,1d"
>> means "use comma as 1000 separator"?
>
> They both mean use the comma for the thousands separator. The decimal
> separator only gets overridden as part of the precision specification if
> provided: format(1234, "8,1f") --> ' 1234,0'
So I misread, but it is exceedingly subtle indeed: apparently if
there's *one* special character it's the decimal point with 'f' and
the thousands separator with 'd'; only 'f' supports *two* special
characters and then the *first* one is the decimal point.
The fact that we need so many emails to sort this out makes it clear
that this proposal will lead to endless user confusion.
> Originally, I proposed prefixing the thousands separator with the letter T:
> format(1234, "8T,d") --> ' 1,234'. That made it crystal
> clear that the next character was the thousands separator. But people found
> it to be ugly and reacted badly. Eric then noticed that the T wasn't
> essential as long as the decimal separator is tightly associated with the
> precision specifier.
>
> If you find that to be screwy, then I guess Nick comma-only alternative
> wins.
Yes.
> Or, there is an alternative that is a little more flexible. Make the
> thousands separator one of SPACE, UNDERSCORE, COMMA, or APOSTROPHE, leaving
> out the DOT which is reserved to be the sole decimal separator. That is
> unambiguous but doesn't help folks who want both a DOT thousands separator
> and COMMA decimal separator.
Right. Let's go ahead with Nick's proposal and put ways of specifying
alternate separators (either via the locale or hardcoded) on the back
burner
Note that, unlike with the original % syntax, in .format() strings we
can easily append extra syntax to the end. E.g. format(1234.5,
"08,.1f;L"} could mean "use the locale", wherease format(1234.5,
"08,.1f;T=_;D=,") could mean "use '_' for thousands, ',' for decimal
point. But please, let's put this off and get Nick's simple proposal
in first.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-ideas
mailing list