PEP 331: Locale-Independent Float/String Conversions

  • Thread starter Christian Robottom Reis
  • Start date
C

Christian Robottom Reis

The LC_NUMERIC 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.

Take care,
 
P

P

Christian said:
The LC_NUMERIC 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.
 
P

P

Christian said:
The LC_NUMERIC 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.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

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'

Indeed. The second one is incorrect usage of the function.

Feel free to submit patches. However, make sure they work on all
relevant platforms.

Regards,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top