Couple functions I need, assuming they exist?

Duncan Booth duncan.booth at invalid.invalid
Mon Jun 20 11:51:07 EDT 2005


Peter Hansen wrote:

>> The target of the problems (my daughter) would prefer that the thousands
>> be delimited.  Is there a string function that does this?
> 
> You refer to something like putting a comma between groups of three 
> digits, as in 1,000?  This is locale-specific, and there's a "locale" 
> module that should have what you need.

>>> import locale
>>> locale.setlocale(locale.LC_ALL, '')
'English_United Kingdom.1252'
>>> print locale.format("%d", 1000000, True)
1,000,000
>>> print locale.format("%.2f", 1000000, True)
1,000,000.00
>>> locale.setlocale(locale.LC_ALL, 'fr')
'French_France.1252'
>>> print locale.format("%d", 1000000, True)
1 000 000
>>> print locale.format("%.2f", 1000000, True)
1 000 000,00




More information about the Python-list mailing list