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:,@1}".format(12345, loc)
'12,345'
...
>>> "UK says {value:,....@uk} and France says {value:,....@france}".format(value=12345, uk=uk_loc, france=france_loc)
'UK says 1,234.5 and France says 1 234,5'

Comments?
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to