Search code examples
pythonpython-3.xformatlocale

How to format numbers by (several different) locales in Python 3


Is there a correct way to format numbers by locale (getting the correct decimal separator) without modifying global state? This is for text generation server-side, so setlocale is not a good idea, and Babel does not yet support Python 3


Solution

  • Unfortunately, the locale module gets and sets global state. This is intrinsic to the design of locale.

    The various workarounds include setting locks or calling a subprocess as a service.