470,613 Members | 2,311 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,613 developers. It's quick & easy.

PEP 331: Locale-Independent Float/String Conversions


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,
--
Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 3361 2331
Jul 18 '05 #1
3 2043
P
Christian Robottom Reis wrote:
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.
Jul 18 '05 #2
P
Christian Robottom Reis wrote:
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.
Jul 18 '05 #3
P@draigBrady.com wrote:
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
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Ksenia Marasanova | last post: by
2 posts views Thread by Jorgen Grahn | last post: by
1 post views Thread by Cagdas Ozgenc | last post: by
3 posts views Thread by robert | last post: by
2 posts views Thread by Daniele C. | last post: by
reply views Thread by Roman Bertle | last post: by
reply views Thread by Gabriel Genellina | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.