[Python-ideas] Rough draft: Proposed format specifier for a thousands separator (discussion moved from python-dev)

Raymond Hettinger python at rcn.com
Thu Mar 12 20:51:07 CET 2009


[Jim Jewett]
> Fair enough.  But what does a thousands separator provide that the "n"
> type doesn't already provide?  (Well, except that n isn't as well
> known  -- but initially this won't be either.)

It's nice to be have a non-locale aware alternative so you can say
explicitly what you want.  This is especially helpful in Guido's example
where you need to format for a different locale than the one that is
currently on your machine (i.e. the global state doesn't match the target).

FWIW, C-Sharp provides both ways, a locale aware "n" format and
a hard-wired explicit thousands separator.  See the updated PEP for
examples and a link.


> Do you want to avoid using locale even in the background?

I thought locale was always there.


> Do you want to avoid having to set a locale in the program startup?

Yes.  I don't think most casaul users should have to figure that out.  
It's a little to magical and arcane:
    >>> import local
    >>> locale.setlocale(locale.LC_ALL, 'English_United States.1252')
> Do you want a better default for locale?

The default does suck:

    >>> format(1237, "n")
    '1237'


> Do you really want a different type, such as "m" for money?

I don't but I'm sure someone does.  I did write a money formatter
sample recipe for the decimal docs so people would have something
to model from.

FWIW, I've always thought it weird that the currency symbol could
shift with a locale setting.  ISTM, that if you change the symbol, you
also have to change the amount that goes with it :-)


Raymond



More information about the Python-ideas mailing list