[Python-Dev] locale and LC_NUMERIC

Neal Norwitz nnorwitz at gmail.com
Mon Jan 9 09:24:18 CET 2006


On 1/8/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> Neal Norwitz wrote:
> > 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?
>
> I feel I'm lacking some link here: why do you think we should do that?

neal at janus ~/build/python/svn/clean-ish $ LC_ALL=de_DE ./python
>>> import locale
>>> locale.setlocale(locale.LC_ALL)
'C'
>>> locale.setlocale(locale.LC_ALL, 'de_DE')
'de_DE'

I would have expected the first call to setlocale() to return de_DE. 
/f solution of adding a flag to the test runner should work for the
bug report I mentioned.  Part of the reason why I asked was because
I'm confused by the current behaviour.  Is the first call to
setlocale() supposed to return C?  If so, always?  I was looking for
some way for the initial call to setlocale() to return de_DE or
whatever other locale I set.

> What does "start with the correct locale" mean? What is the "correct
> locale"? Python should work in any locale,

Hopefully my explanation above answered all those questions.

> and locale.format
> should always give the locale-specific formatting, whereas "%f" % value
> should always give the result from the "C" locale (regardless of
> whether the application has called setlocale or not).

Right.  I'm working on a patch for this problem which is independent
of what I was asking.  I really should have started a new thread, but
I wasn't completely sure when I asked if there was a relationship. 
Also, in Georg's snippet, he didn't show that he was setting the
locale, only what it was set to.

n


More information about the Python-Dev mailing list