473,417 Members | 1,628 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,417 software developers and data experts.

locale.setlocale problems

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)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import locale
locale.setlocale(locale.LC_ALL, 'nl_NL') 'nl_NL' locale.format('%0.2f', 0.123) '0.12'

(It should return: 0,12)
On the server, it doesn't work at all:

Python 2.3 (#1, Jan 4 2004, 14:30:19)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information. import locale
locale.setlocale(locale.LC_ALL, 'nl_NL')

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.3/locale.py", line 381, in setlocale
return _setlocale(category, locale)
locale.Error: locale setting not supported

All I want to do, is format numbers with comma as decimal separator in
a web application. Is there some system libraries I have to install, to
make locale work?
And the last question: when I change locale in a Python application, it
affects only the current namespace, right? I hope so... :)

Thanks!
Ksenia.

Jul 18 '05 #1
3 3215
Ksenia Marasanova wrote:
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)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Yes. OS X, unfortunately, doesn't really support the C locale APIs.
More precisely, it supports the functions, but they have no meaningful
effect. Python relies on the operating system here, so please bring
this up with your OS vendor.
On the server, it doesn't work at all:

Python 2.3 (#1, Jan 4 2004, 14:30:19)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'nl_NL')

Likewise. Apparently, the operating system does not support that locale,
so Python cannot support it, either.
All I want to do, is format numbers with comma as decimal separator in a
web application. Is there some system libraries I have to install, to
make locale work?
On freebsd4, this may help, but you would need to ask in a FreeBSD
newsgroup. On OS X, you just have to wait a couple more OS releases.
And the last question: when I change locale in a Python application, it
affects only the current namespace, right? I hope so... :)


Not sure what a namespace is, in this context, but I guess the answer is
"yes".

Regards,
Martin
Jul 18 '05 #2
> Python relies on the operating system here, so please bring
this up with your OS vendor.


Okay, I got it now. Thanks for the explanation.
And the last question: when I change locale in a Python application,
it affects only the current namespace, right? I hope so... :)


Not sure what a namespace is, in this context, but I guess the answer
is
"yes".


With 'namespace' I meant only the module when the locale is changed, so
it not affects other scripts that run at the same time on the system. I
misunderstood locale as being some system-wide 'registry' which
remembers the changes in it. (have some vague, bad memories about
changing locale in an ASP application... :-)

Thank you,
Ksenia.
Jul 18 '05 #3
On Sat, 02 Oct 2004 11:26:47 +0200, Ksenia Marasanova <ks****@ksenia.nl> wrote:
Python 2.3 (#1, Jan 4 2004, 14:30:19)
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4
Type "help", "copyright", "credits" or "license" for more information.
import locale
locale.setlocale(locale.LC_ALL, 'nl_NL') Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.3/locale.py", line 381, in setlocale
return _setlocale(category, locale)
locale.Error: locale setting not supported
FreeBSD is very strict for locale names. You should write it like this:

Python 2.3.4 (#2, Aug 21 2004, 20:09:51)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
import locale
locale.setlocale(locale.LC_ALL, 'nl_NL.ISO8859-1') 'nl_NL.ISO8859-1' locale.format('%0.2f', 0.123)
'0,12'
Python relies on the operating system here, so please bring
this up with your OS vendor.
Okay, I got it now. Thanks for the explanation.


There's a mailing list "py****@FreeBSD.org" for this purpose.
You can subscribe the list at
http://lists.freebsd.org/mailman/lis...freebsd-python
And the last question: when I change locale in a Python application,
it affects only the current namespace, right? I hope so... :)


Not sure what a namespace is, in this context, but I guess the answer
is
"yes".


With 'namespace' I meant only the module when the locale is changed, so
it not affects other scripts that run at the same time on the system. I
misunderstood locale as being some system-wide 'registry' which
remembers the changes in it. (have some vague, bad memories about
changing locale in an ASP application... :-)


locale stuff are process-scope variable. (In FreeBSD, global libc
variable _CurrentRuneLocale). If you change the locale, it affects
all the namespaces/modules/threads but will not affect system
settings or other processes.

Hye-Shik
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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,...
2
by: Mike Conmackie | last post by:
Greetings, Is there any way to force strftime() to ignore locale settings when formatting the resulting string? I have a requirement to create a specific date-time string format in UTC. ...
3
by: gelbeiche | last post by:
I have a question regarding the following small C program. #include <locale.h> int main() { char* loc = 0; char before,after; int i;
0
by: Manlio Perillo | last post by:
Regards. I have a few questions about locale handling on Windows. The first: why getlocale() returns (None, None) when the locale is 'C'? The second is: why this code fails?: >>> loc, enc...
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: 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...
5
by: Sashi Asokarajan | last post by:
Hello, recently I stepped over Strotrup's TC++PL (third ed.) Chapter D.1 where the localization support of the C++ stdlib is explained. http://www.research.att.com/~bs/3rd_loc.pdf ] ...
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,...
0
by: Matthias Huening | last post by:
Hi, I have problems using tkFileDialog under Linux (Ubuntu 8.04 in my case, but other Linuxes seem to show the same behaviour). The following works fine: import tkFileDialog f =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.