|
Damjan
gdamjan at mail.net.mk
Tue May 22 01:32:22 EST 2001
> I've come across a problem with mod_python (2.7.2
> compiled with Python 2.0 --with-threads=no) on Linux
> (RH 7.0) regarding locale.
>
> the following code (mptest.py):
> -----------------
> from mod_python import apache
> from locale import setlocale,LC_ALL,format
>
>
> def handler(req):
> req.content_type = "text/plain"
> req.send_http_header()
> setlocale(LC_ALL,'')
This command set the locale to the one specified with the LC_xx or LANG
enviroment variables.
> a = 123123231.323
> req.write("The formatted version of the number %s
> is %s" % (a,format('%.2f',a,1)))
> return apache.OK
>
> Produces:
> ----------------------
> The formatted version of the number 123123231.323 is
> 123123231.32
>
> Rather than the expected
> -----------------------
> ....123,123,231.32
When you run your scripts interactively you have defined some locale by the
LC_xxx or the LANG variable. On the other side, it seems that your Apache
process is using the default locale (C), so that's why the formating looks
like that.
I would use -- setlocale(LC_ALL,'mk_MK') -- to get macedonian localization in
python scripts, but perhaps you would like to change this on a per user
preference.
--
Damjan Georgievski | Дамјан Георгиевски
Skopje, Macedonia | Скопје, Македонија
|