[Python-ideas] String formatting utility functions

Eric Smith eric at trueblade.com
Fri Mar 13 12:27:14 CET 2009

Jim Jewett wrote:
 > On 3/12/09, Eric Smith <eric at trueblade.com> wrote:
 >> Eric Smith wrote:
 >>> ... formats
 >>> a number based on the same settings that are in the locale, but not
 >>> actually use the locale.
 > ...
 >> The key point is that it takes everything as parameters and doesn't use
 >> any global state. In particular, it by itself would not reference the
 >> locale.
 > Why not?  You'll need *some* default for decimal_point, and the one
 > from localeconv makes at least as much sense as a hard-coded default.

I guess you could do this, but I can't see it ever actually being used 
that way. Do you really want to only specify that you're using commas 
for thousands, then find that someone has switched the locale to one 
where a comma is the decimal character?

new_util_func(1234.56, thousands_sep=',')

Best to be explicit on what you're expecting. My use case for this 
function is one where all of the arguments are known and specified every 
time. Specifically it's for implementing 'n' formatting for Decimal or 
other numeric types. You will either know the arguments, or want to use 
every one of them from the locale. If you're using the locale, just call 
localeconv() and use every value you get back. I don't have a 
mix-and-match use case.


More information about the Python-ideas mailing list