[Python-Dev] Re: PEP 331: Locale-Independent Float/String Conversions (original) (raw)

P at draigBrady.com P at draigBrady.com
Tue Jul 20 13:24:34 CEST 2004


Christian Robottom Reis wrote:

The LCNUMERIC PEP has just been allocated a number, PEP 331.

http://www.python.org/peps/pep-0331.html Though the code has been integrated, comments and corrections to the PEP would be appreciated -- in particular, Tim might have some comments on the thread-safety issues, Gustavo, about the implementation or Martin, about the actual constraints on the change itself.

Oh cool. Since we're now setting LC_NUMERIC at the glibc level can we fix up locale.format. It's is very simplistic at the moment as it groups %s items as numbers: locale.format("%s",1234,1) -> '1,234' and treats non numbers as numbers: locale.format("%s\n",1234,1) -> '12,34\n'

This could be fixed by only allowing numbers in? Better though would be to pass things down to glibc's snprintf I.E. use the glibc facility of the ' modifier. e.g "%'d" This applies to any decimal conversion (i,d,u,f,F,g,G) You wouldn't have to use it directly, instead in locale.format() you could add in a ' in the appropriate places. Note the ' formating mechanism is SUSV2 not just glibc

Pádraig.



More information about the Python-Dev mailing list