Rough draft: Proposed format specifier for a thousands separator

Rhodri James rhodri at wildebst.demon.co.uk
Mon Mar 16 18:41:47 EDT 2009


On Mon, 16 Mar 2009 02:36:43 -0000, MRAB <google at mrabarnett.plus.com>  
wrote:

> The field name can be an integer or an identifier, so the locale could
> be too, provided that you know where to look it up!
>
>      financial = Locale(group_sep=",", grouping=[3])
>      print("my number is {0:10n:{fin}}".format(1234567, fin=financial))
>
> Then again, shouldn't that be:
>
>      fin = Locale(group_sep=",", grouping=[3])
>      print("my number is {0:{fin}}".format(1234567, fin=financial))

Except that loses you the format, since the locale itself is a collection
of parameters the format uses.  The locale knows how to do groupings, but
not whether to do them, nor what the field width should be.  Come to think
of it, it doesn't know whether to use the LC_NUMERIC grouping information
or the LC_MONETARY grouping information.  Hmm.

I can't believe I'm even suggesting this, but how about:

   print("my number is {fin.format("10d", {0}, True)}".format(1235467,  
fin=financial))

assuming the locale.format() method remains unchanged?  That's horrible,
and I'm pretty sure it can't be right, but I'm too tired to think of
anything more sensible right now.

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list