473,226 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

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 2127
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Epler | last post by:
I'd expect these two to be identical, but they don't seem to be. >>> import locale >>> locale.setlocale(locale.LC_ALL, "fr_FR") 'fr_FR' >>> locale.nl_langinfo(locale.DAY_1) 'dimanche' >>> #...
3
by: Ksenia Marasanova | last post by:
Hi, I have some problems with locale module. On my workstation, changing locale doesn't have effect: Python 2.3 (#1, Sep 13 2003, 00:49:11) on darwin Type "help", "copyright", "credits" or...
2
by: Jorgen Grahn | last post by:
I'm sitting here with a Debian Linux 'Woody' system with the default Python 2.2 installation, and I want the re module to understand that re.compile(r'\W+'. re.LOCALE) doesn't match my national,...
1
by: Cagdas Ozgenc | last post by:
Greetings. I am confused about C++ standard library locale stuff. It seems as if the implementations of locales are not part of the library, but only some guideline classes are there. What is...
0
by: | last post by:
Hi all, running the following code as an console application: #include <locale> #include <iostream> #include <sstream> #include <tchar.h> using namespace std;
3
by: robert | last post by:
Why can the default locale not be set by its true name? but only by '' ? : PythonWin 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win32. (None, None) Traceback (most recent call last): File...
2
by: cris | last post by:
Hi, I got trouble when I try to change the locale used in a program foo.cc // ----------------- begin #include <iostream> #include <locale> #include <exception> using namespace std; int...
2
by: Daniele C. | last post by:
I will report a snippet from http://php.net/setlocale I spent about 2 seconds before thinking: can it really be? I mean, is there no way to set locale info per thread? And after a brief web...
0
by: Roman Bertle | last post by:
Hello, I try to format monetary values using the locale module, python2.5: Python 2.5.2a0 (r251:54863, Jan 3 2008, 17:59:56) on linux2 Type "help", "copyright", "credits" or "license" for...
0
by: Gabriel Genellina | last post by:
En Tue, 26 Aug 2008 07:52:21 -0300, Robert Rawlins <robert.rawlins@thinkbluemedia.co.ukescribi�: Probably you don't have support for 'de_DE' locale. Try using locale.setlocale(locale.LC_ALL,...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.