[Python-ideas] Rough draft: Proposed format specifier for a thousands separator (discussion moved from python-dev)
eric at trueblade.com
Thu Mar 12 10:33:54 CET 2009
Thanks for doing this, Raymond.
I don't have any comments on the specific proposals, yet. I'm still
thinking it over. But here are a few comments.
Raymond Hettinger wrote:
You might want to mention the existing 'n' format type. I don't think
it's widely known. It handles the odd cases of locales that have odd
groupings, such as James Knight's example from India (1,00,00,00,000).
James: If you know the locale name for that, I'd like to know it. It
would be handy for testing.
floats are not terribly useful for 'n', however:
>>> format(1000000, 'n')
>>> format(1000000.111111, 'n')
>>> format(100000.111111, 'n')
> Proposal I (from Nick Coghlan]:
> A comma will be added to the format() specifier mini-language:
Could you add the existing PEP-3101 specifier, just so we know what
we're changing (and so that I don't have to look it up constantly!)?
(As an aside, I copied this from
http://docs.python.org/library/string.html#formatstrings, I just noticed
that PEP 3101 differs in the name of the width/minwidth field.)
> for hundreds or ten-thousands), but iIt comes at the expense of
> Also, it makes it
> more challenging to write custom __format__ methods that follow the
> format specification mini-language.
For this exact reason, I've always wanted to add a method somewhere that
parses the mini-language. The code exists in the C implementation, it
would just need to be exposed, probably returning a namedtuple with the
> For the locale module, just the "T" is necessary in a formatting string
> since the tool already has procedures for figuring out the actual
> separators from the local context.
Is this needed at all? That is, having just the "T"? How is this
different from using type=n? Having asked the question, I guess the
answer is it lets you use it with the more useful float type=f.
> Comments and suggestions are welcome but I draw the line at Mayan
> numbering conventions ;-)
That's only a problem until December 21, 2012 anyway!
More information about the Python-ideas