Terry Reedy wrote: > On 4/27/2014 6:40 AM, Kev Dwyer wrote: >> Igor Korot wrote: >> >>> Hi, ALL, >>> I need to perform a subj. >>> Looking at the Google I found following thread with explanation: >>> >>> http://stackoverflow.com/questions/36139/how-do-i-sort-a-list-of- strings- >> in-python >>> >>> However, doing this in my python shell produces an error: >>> >>> C:\Documents and Settings\Igor.FORDANWORK\My >>> Documents\GitHub\webapp>python Python 2.7.5 (default, May 15 2013, >>> 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> import locale >>>>>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') >>> Traceback (most recent call last): >>> File "<stdin>", line 1, in <module> >>> File "c:\python27\lib\locale.py", line 547, in setlocale >>> return _setlocale(category, locale) >>> locale.Error: unsupported locale setting >>>>>> >>> >>> What is wrong with this? >>> >>> Thank you. >> >> >> Hello Igor, >> >> Windows maintains it's own names for locales, so you need to >> supply the Windows name if you're workong on Windows. >> >> You might find these links helpful: >> >> http://stackoverflow.com/questions/19709026/how-can-i-list-all-available- >> windows-locales-in-python-console > > This one says to look at locale.locala_alias, but that is not helpful. > > >>> for k, v in la.items(): > if v.startswith ('en') and 'UTF' in v: > print(k, " # ", v) > > universal.utf8@ucs4 # en_US.UTF-8 > > But that local does not work on my machine. > > >>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') > Traceback (most recent call last): > File "<pyshell#20>", line 1, in <module> > locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') > File "C:\Programs\Python34\lib\locale.py", line 592, in setlocale > return _setlocale(category, locale) > locale.Error: unsupported locale setting > > locale.locale_alias must not be machine limited. > >> https://mail.python.org/pipermail/python-list/2009-February/525427.html > > This merely says to look at a now dead link. My mistake for not checking the link; this one works: http://msdn.microsoft.com/en-us/library/hzz3tw78 >
Hello Terry, Regarding your second point, my mistake in not checking the link: I'd seen a similar one elsewhere and assumed they were the same. This link should work: http://msdn.microsoft.com/en-us/library/hzz3tw78 As to your first point, you're right, it seems setlocale(locale.LC_ALL, 'en_US.UTF-8') doesn't work on Windows. It seems the locale name needs to be one of the aliases provided at http://msdn.microsoft.com/en-us/library/39cwe7zf, so for example locale.setlocale(locale.LC_ALL, 'usa') returns 'English_United States.1252'. Do you know if this is something people programming on Windows should just be aware of, or is there a case for a hint of some kind in the locale module documentation? Cheers, Kev -- https://mail.python.org/mailman/listinfo/python-list