[Python-Dev] Locale-specific formatting (original) (raw)
R. David Murray rdmurray at bitdance.com
Sat Dec 18 05:00:28 CET 2010
- Previous message: [Python-Dev] Locale-specific formatting
- Next message: [Python-Dev] Locale-specific formatting
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, 18 Dec 2010 00:08:47 +0000, MRAB <python at mrabarnett.plus.com> wrote:
I had a thought about locale-specific formatting.
Currently, when we want to do locale-specific formatting we use the locale module like this: >>> locale.format("%d", 12345, grouping=False) '12345' >>> locale.format("%d", 12345, grouping=True) '12,345' This makes it harder to use more than one locale at a time, or one which is different from the default. My thought was that we could specify a locale in the format specification mini-language and the parameter list of str.format, something like this: >>> loc = locale.getlocale() >>> "{0:@1}".format(12345, loc) '12345' >>> "{0:, at 1}".format(12345, loc) '12,345' ... >>> "UK says {value:,.1f at uk} and France says {value:,.1f at france}".format(value=12345, uk=ukloc, france=franceloc) 'UK says 1,234.5 and France says 1 234,5' Comments?
There was at least one long thread on this on python-ideas. Probably worth finding and reading before proceeding with a new discussion... :)
I think it was part of the discussion that ultimately led to PEP 378.
-- R. David Murray www.bitdance.com
- Previous message: [Python-Dev] Locale-specific formatting
- Next message: [Python-Dev] Locale-specific formatting
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]