Rough draft: Proposed format specifier for a thousands separator

andrew cooke andrew at acooke.org
Fri Mar 13 12:06:51 CET 2009


Raymond Hettinger wrote:
> [Lie Ryan]
>> A hyphotetical code using conv function and the microlanguage could look
>> like this:
>>
>>  >>> num = 213210.3242
>>  >>> fmt = create_format(sep='-', decsep='@')
>>  >>> print fmt
>> 50|\/|3_v3ry_R34D4|3L3_C0D3
>>  >>> '{0!{1}}'.format(num, fmt)
>> '213-210 at 3242'
>
> LOL, it's like APL all over again ;-)
>
> FWIW, the latest version of the proposal is dirt simple:
>
>>>> format(1234567, 'd')       # what we have now
> '1234567'
>>>> format(1234567, ',d')      # proposed new option
> '1,234,567'
>>>> format(1234.5, '.2f')      # what we have now
> '1234.50'
>>>> format(1234.5, ',.2f')     # proposed new option
> '1,234.50'

would it break anything to also allow

>>> format(1234567, 'd')       # what we have now
 '1234567'
>>> format(1234567, '.d')      # proposed new option
 '1.234.567'
>>> format(1234.5, ',2f')      # proposed new option
 '1234,50'
>>> format(1234.5, '.,2f')     # proposed new option
 '1.234,50'

because that would support a moderate chunk of the non-english speaking
users and seems like a natural extension.

(i'm still not sure this is that great an idea - if you think using a
locale is "rocket science" then perhaps your excess energy would be better
spent making locale easier, rather than tweaking this behaviour for a
subset of users?)

andrew





More information about the Python-list mailing list