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

Nathaniel Smith njs at pobox.com
Sun Jan 28 20:48:52 EST 2018

On Sun, Jan 28, 2018 at 5:31 PM, David Mertz <mertz at gnosis.cx> wrote:
> 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.

I don't understand the format mini-language well enough to know what
would fit in, but maybe some way to (a) request localified formatting,
(b) some way to explicitly say which locale you want to use? Like if
"h" means "human friendly", it might be something like:

f"In the current locale x is {x:h.2f}, in Indian format it is {x:h(en_IN).2f}"


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

More information about the Python-ideas mailing list