[Python-ideas] Format mini-language for lakh and crore

Nathaniel Smith njs at pobox.com
Sun Jan 28 19:27:24 EST 2018

On Sun, Jan 28, 2018 at 5:46 AM, Eric V. Smith <eric at trueblade.com> wrote:
> If I recall correctly, we discussed this at the time, and the problem with
> locale is that it's not thread safe. I agree that if it were, it would be
> nice to be able to use it, either with 'n', or in some other mode just for
> grouping.
> The underlying C setlocale()/localeconv() just isn't very friendly to this
> use case.

POSIX.1-2008 added thread-local locales (say that 3x fast); see
uselocale(3). This appears to be supported on Linux (since glibc 2.3,
which is older than all supported enterprise distros), MacOS, and the
BSDs, but not Windows. OTOH Windows, MacOS, and the BSDs all seem to
provide the non-standard sprintf_l, which takes an explicit locale to

So it looks like all mainstream OSes actually make it possible to use
a specific locale to do arbitrary formatting in a thread-safe way.


Nathaniel J. Smith -- https://vorpus.org

More information about the Python-ideas mailing list