I actually didn't know about `locale.format("%d", 10e9, grouping=True)`. But it's still much less general than having the option in the f-string/.format() mini-language. This is really about the formatted string, not necessarily about the locale. So, e.g. I'd like to be able to write:
>>> print(f"In European format x is {x:,.2f}, in Indian format it is {x:`.2f}") I don't want the format necessarily to be some pseudo-global setting, even if it can get stored in thread-locals. That said, having a locale-aware symbol for delimiting numbers in the format mini-language would also not be a bad thing. On Sun, Jan 28, 2018 at 4:27 PM, Nathaniel Smith <n...@pobox.com> wrote: > On Sun, Jan 28, 2018 at 5:46 AM, Eric V. Smith <e...@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 > use. > > 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. > > -n > > -- > Nathaniel J. Smith -- https://vorpus.org > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/