python-dev
[Prev] Thread [Next] | [Prev] Date [Next]
Re: [Python-Dev] Formatting mini-language suggestion Raymond Hettinger Wed Mar 11 20:00:48 2009
[James Y Knight]
You might be interested to know that in India, the commas don't come every 3 digits. In india, they come every two digits, after the first three. Thus one billion = 1,00,00,00,000. How are you gonna represent *that* in a formatting mini-language? :)
It is not the goal to replace locale or to accomodate every possible convention. The goal is to make a common task easierfor many users. The current, default use of the period as a decimal point has not proven to be problem eventhough that convention is not universal. For a thousands separator, a comma is a decent choice that makes it easy follow-on with s.replace(',', '_') or somesuch.
This simple utility could help a lot of programmers make their output look more professional and readable. I hope the idea doesn't get sunk by a desire to over-parameterize and cover every possible use case. My pocket calculators all support thousands separators but in Python, we have to do a funky dance for even this most basic bit of formatting. I'd like to think that in 2009 we could show a little progress beyond C's printf() or Fortran's write() formats. Raymond
import locale locale.setlocale(locale.LC_ALL, 'English_United States.1252')
'English_United States.1252'
conv = locale.localeconv() # get a mapping of conventions x = 1234567.8 locale.format("%d", x, grouping=True)
'1,234,567' _______________________________________________ Python-Dev mailing list [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/alexiscircle%40gmail.com
- [Python-Dev] Formatting mini-language suggestion Raymond Hettinger
- Re: [Python-Dev] Formatting mini-language suggestion Antoine Pitrou
- Re: [Python-Dev] Formatting mini-language suggestion Guido van Rossum
- Re: [Python-Dev] Formatting mini-language suggestion Raymond Hettinger
- Message not available
- Re: [Python-Dev] Formatting mini-language suggestion Guido van Rossum
- Re: [Python-Dev] Formatting mini-language suggestion Nick Coghlan
- Re: [Python-Dev] Formatting mini-language suggestion James Y Knight
- Re: [Python-Dev] Formatting mini-language suggestion Raymond Hettinger <=
- Re: [Python-Dev] Formatting mini-language suggestion Nick Coghlan
- Re: [Python-Dev] Formatting mini-language suggestion James Y Knight
- Re: [Python-Dev] Formatting mini-language suggestion Lie Ryan
- Re: [Python-Dev] Formatting mini-language suggestion Raymond Hettinger
- Re: [Python-Dev] Formatting mini-language suggestion Jeroen Ruigrok van der Werven
- Re: [Python-Dev] Formatting mini-language suggestion Ben Finney
- Re: [Python-Dev] Formatting mini-language suggestion Greg Ewing
Re: [Python-Dev] Formatting mini-language suggestion Greg Ewing
- Re: [Python-Dev] Formatting mini-language suggestion Stephen J. Turnbull
- Re: [Python-Dev] Formatting mini-language suggestion Greg Ewing