locale.getlocale() strange behaviour

Jeff Epler jepler at unpythonic.net
Tue Mar 2 21:09:26 EST 2004


Just as in C programs, the LANG and LC_* environment variables have no
effect until setlocale is called with "" as the second argument.

On my system:
$ echo $LANG
en_US.UTF-8
$ python -c 'import locale; print locale.getlocale()'
(None, None)
$ python -c 'import locale; locale.setlocale(locale.LC_ALL, ""); print locale.getlocale()'
['en_US', 'utf']

In Python2.2 on my system, setlocale() is called by rl_initialize() when
I run the interactive interpreter.
$ python -c 'import locale; import readline; print locale.getlocale()'
['en_US', 'utf']
this may explain the behavior you noticed.

Jeff




More information about the Python-list mailing list