Rough draft: Proposed format specifier for a thousands separator

Rhodri James rhodri at wildebst.demon.co.uk
Mon Mar 16 03:04:27 CET 2009


On Sun, 15 Mar 2009 19:00:43 -0000, MRAB <google at mrabarnett.plus.com>  
wrote:

> Rhodri James wrote:
> [snip]
>> Frankly, I'd much rather fix the locale system and extend
>> the format syntax to override the default locale.  Perhaps
>> something like
>>    financial = Locale(group_sep=",", grouping=[3])
>>   print("my number is {0:10n:financial}".format(1234567))
>>  It's hard to think of a way of extending "%" format strings
>> to cope with this that won't look utterly horrid, though!
>>
> The problem with your example is that it magically looks for the locale
> name "financial" in the current namespace.

True, to an extent.  The counter-argument of "Is it so much
more magical than '{keyword}' looking up the object in the
parameter list" suggests a less magical approach would be to
make the locale a parameter itself:

   print("my number is {0:10n:{1}}".format(1234567, financial)

> Perhaps the name should be
> registered somewhere like this:
>
>      locale.predefined["financial"] = Locale(group_sep=",", grouping=[3])
>      print("my number is {0:10n:financial}".format(1234567))

I'm not sure that I don't think that *more* magical than my
first stab!  Regardless of the exact syntax, do you think
that being able to specify an overriding locale object (and
let's wave our hands over what one of those is too) is the
right approach?

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



More information about the Python-list mailing list