Author eryksun
Recipients Arfrever, BreamoreBoy, eryksun, lemburg, loewis, serhiy.storchaka, steve.dower, tim.golden, zach.ware
Date 2015-02-12.15:35:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
For 3.5 this affects Windows as well, since the new CRT supports RFC1766 language codes, but only without a codepage spec:

    Python 3.5.0a1 (v3.5.0a1:5d4b6a57d5fd, Feb  7 2015, 18:15:14) 
    [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import locale
    >>> locale.setlocale(locale.LC_ALL, 'en-GB')

    >>> locale.getlocale()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Program Files\Python35\lib\", line 578, in getlocale
        return _parse_localename(localename)
      File "C:\Program Files\Python35\lib\", line 487, in _parse_localename
        raise ValueError('unknown locale: %s' % localename)
    ValueError: unknown locale: en-GB

On Vista+ (since 3.5 drops XP support) the codepage can be queried easily via GetLocaleInfoEx:

    >>> from ctypes import *
    >>> GetLocaleInfoEx = WinDLL('kernel32').GetLocaleInfoEx
    >>> info = (c_wchar * 100)()
    >>> GetLocaleInfoEx("en-GB", LOCALE_IDEFAULTANSICODEPAGE, info, len(info)) 
    >>> info.value
    >>> GetLocaleInfoEx("zh-CN", LOCALE_IDEFAULTANSICODEPAGE, info, len(info))
    >>> info.value                                                            

Note that Windows follows the RFC spec here (not POSIX), using a hyphen instead of an underscore. 

This is a bit of tangent, but for the Windows full language_country.codepage form, the X-11 based locale_alias dict is generally useless. So, contrary to the docs, on Windows getlocale doesn't return the language code in RFC 1766 form. In some cases it does, but only by chance.
Date User Action Args
2015-02-12 15:35:47eryksunsetrecipients: + eryksun, lemburg, loewis, tim.golden, Arfrever, BreamoreBoy, zach.ware, serhiy.storchaka, steve.dower
2015-02-12 15:35:47eryksunsetmessageid: <>
2015-02-12 15:35:47eryksunlinkissue20088 messages
2015-02-12 15:35:47eryksuncreate