By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 1,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

locale.setlocale problems

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
> 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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.