[Python-Dev] locale and LC_NUMERIC

Neal Norwitz nnorwitz at gmail.com
Mon Jan 9 08:41:29 CET 2006


On 1/8/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> Georg Brandl wrote:
> >  >>> "%f" % 1.0
> > '1.000000'
> >  >>> u"%f" % 1.0
> > u'1,000000'
> >
> > Is this intended? This breaks test_format on my box when test_builtin (method
> > test_float_with_comma) is executed first.
>
> No. %-formatting should always use the C locale. One should use
> locale.format to get locale-aware formatting.

I know very little about locale's.  /f assigned me a bug
http://python.org/sf/1391872 which suggests I run all the tests in a
different locale than C.  I think this is a good idea, but when I set
LANG or LC_ALL or LC_CTYPE in the env't the locale isn't set without
me calling locale.setlocale().  Shouldn't we maintain the value from
the env't?

The problem I found is in Python/pythonrun.c.  At least I think that's
the problem.  Around line 230-240 we call setlocale(NULL), then call
setlocale("").  Then later on we restore the locale by calling
setlocale() with the return result from setlocale(NULL).

The man page on my box (gentoo) says that passing NULL returns the
current locale() while passing "" sets the locale from the env't
variable.  Should we just capture the results of setlocale("")?

If my understanding is wrong, how can I start python with the correct
locale?  It seems like that I'm confused since this problem hasn't
seemed to come up before.

n


More information about the Python-Dev mailing list