[issue20999] setlocale, getlocale succession --> ValueError or (None, None)

albertjan report at bugs.python.org
Sat Mar 22 21:34:42 CET 2014


albertjan added the comment:

Ok, I know this is closed as a duplicate, but I am pasting some additional info here for reference. All info is about the FIRST system of the original message

## The locale settings
fomcls-Mac-Pro:Desktop fomcl$ locale
LANG=
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

##  export LANG="en_US.UTF-8" does not fix it.
fomcls-Mac-Pro:Desktop fomcl$ export LANG="en_US.UTF-8"
fomcl-Mac-Pro:Desktop fomcl$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
>>> import locale
>>> locale.getdefaultlocale()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 496, in getdefaultlocale
    return _parse_localename(localename)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8
>>> locale.setlocale(locale.LC_ALL, "")
'en_US.UTF-8/UTF-8/en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/en_US.UTF-8'
>>> locale.getlocale()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 515, in getlocale
    return _parse_localename(localename)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

## export LC_ALL="en_US.UTF-8" makes it all work as expected/desired.
fomcls-Mac-Pro:Desktop fomcl$ export LC_ALL="en_US.UTF-8"
fomcls-Mac-Pro:Desktop fomcl$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
>>> import locale
>>> locale.getdefaultlocale()
('en_US', 'UTF-8')
>>> locale.getlocale()
(None, None)
>>> locale.setlocale(locale.LC_ALL, "")
'en_US.UTF-8'
>>> locale.getlocale()
('en_US', 'UTF-8')

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20999>
_______________________________________


More information about the Python-bugs-list mailing list