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

Raymond Hettinger python at rcn.com
Sat Mar 14 07:08:18 CET 2009


[Nick Coghlan]
> 1. The Single Unix Specification apparently uses an apostrophe as a flag
> in prinft() %-formatting to request inclusion of a thousands separator
> in a locale aware way [1].

We already use C-sharp's "n" flag for a locale aware thousands separator.


> Since the apostrophe is much harder to
> mistake for a period than a comma is, I would modify my "just a flag"
> suggestion to use an apostrophe as the flag instead of a comma:
 . . .
> The output would still use commas though:

That doesn't make sense for two reasons:
1.  Why mark a non-locale aware form with a flag that indicates
     locale awareness in another language.
2.  It seems to be basic bad design to require an apostrophe
     to emit commas.

FWIW, the comma-only version of the proposal is probably going to 
die anyway.  The more flexible alternative evolved to something simple
and direct.  Also, the newsgroup discussion make it abundantly clear 
that half the world will rebel if commas are the only supported option.  


> 2. PEP 3101 *already included* a way to modify the handling of format
> strings in a consistent way: use a custom string.Formatter subclass
> instead of relying on the basic str.format method.
> 
> When the mini language parser is exposed (which I consider a separate
> issue from this PEP), a locale aware custom formatter is going to find a
> "include digit separators" flag far more useful than the overly explicit
> "use this thousands separator and this decimal separator".

Thanks.  Will note that in the PEP when I get a chance.



Raymond



More information about the Python-ideas mailing list