Rough draft: Proposed format specifier for a thousands separator

Rhodri James rhodri at
Tue Mar 17 02:19:27 CET 2009

On Mon, 16 Mar 2009 23:04:58 -0000, MRAB <google at>  

> It should probably(?) be:
>      financial = Locale(group_sep=",", grouping=[3])
>      print("my number is {0:10n:fin}".format(1234567, fin=financial))
> The format "10n" says whether to use separators or a decimal point; the
> locale "fin" says what the separator and the decimal point look like.

That works, and isn't an abomination on the face of the existing syntax.   

I'm rather presuming that the "n" presentation type does grouping.  I've  
only got Python 2.5 here, so I can't check it out (no str.format() method  
and "%n" isn't supported by "%" formatting).  If it does, an "m" type to  
do the same thing only with the LC_MONETARY group settings instead of the  
LC_NUMERIC ones would be a good idea.

This would be my preferred solution to Raymond's original  
comma-in-the-format-string proposal, by the way: add an "m" presentation  
type as above, and tell people to override the LC_MONETARY group settings  
in the global locale.  It's clear that it's a bodge, and weaning users  
onto local locales (!) wouldn't be so hard later on.

Anyway, time I stopped hypothesising about locales and started looking at  
the actual code-base, methinks.

Rhodri James *-* Wildebeeste Herder to the Masses

More information about the Python-list mailing list