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

Nick Coghlan ncoghlan at gmail.com
Sat Mar 14 04:50:25 CET 2009

Joining the discussion over here to add a couple of points that I
haven't seen in Raymond's PEP updates on the checkin list:

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]. 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:

format(1234, "8.1f")     -->    '  1234.0'
format(1234, "8'.1f")    -->    ' 1,234.0'
format(1234, "8d")       -->    '    1234'
format(1234, "8'd")      -->    '   1,234'

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".


[1] http://linux.die.net/man/3/printf

Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list