----- Original Message -----
> From: Mark Lawrence <breamore...@yahoo.co.uk> > To: python-list@python.org > Cc: > Sent: Monday, February 9, 2015 5:02 PM > Subject: Re: locale bug in Python 2.7, 3.3, 3.4 (Win7 64)? > > On 09/02/2015 15:43, Albert-Jan Roskam wrote: >> Hi, >> >> In the locale module we have: >> * setlocale, the setter that also returns something >> * getlocale, the getter that returns the OS-specific locale tuple > (supposedly!) >> >> * getdefaultlocale, the getter that always returns a unix locale tuple >> >> Why are the getlocale() results below sometimes windows-like, sometimes > unix-like? >> It seems that I need to use setlocale(), with only the 'category' > parameter, right? >> >> >> ActivePython 3.3.2.0 (ActiveState Software Inc.) based on >> Python 3.3.2 (default, Sep 16 2013, 23:11:39) [MSC v.1600 64 bit (AMD64)] > on win32 >> Type "help", "copyright", "credits" or > "license" for more information. >>>>> import locale >>>>> locale.getlocale() >> (None, None) # because setocale has not been called yet >> >> >> # works as expected >> >>>>> locale.setlocale(locale.LC_ALL, "") >> 'Dutch_Netherlands.1252' >>>>> locale.getlocale() >> ('Dutch_Netherlands', '1252') >> >> # bug!>>> locale.setlocale(locale.LC_ALL, "german") >> 'German_Germany.1252' >>>>> locale.getlocale() >> ('de_DE', 'cp1252') # incorect, unix-like! >> >> >>>>> locale.setlocale(locale.LC_ALL, > "German_Germany.1252") >> 'German_Germany.1252' >>>>> locale.getlocale() >> ('de_DE', 'cp1252') # incorect, unix-like! >> >> >> # bug! >> >>>>> locale.setlocale(locale.LC_ALL, "spanish") >> 'Spanish_Spain.1252' >>>>> locale.getlocale() >> ('es_ES', 'cp1252') # incorect, unix-like! >> >> >> # works as expected >>>>> locale.setlocale(locale.LC_ALL, "italian") >> 'Italian_Italy.1252' >>>>> locale.getlocale() >> ('Italian_Italy', '1252') # correct! >> >> >> # ... maybe more? >> >> >> Regards, >> >> Albert-Jan >> > > There have been loads of bug reports on the issue tracker about locales. > I suggest that you take a look to see if there is an open issue about > this problem. Hi Mark -Thanks! I checked the bug tracker. Lots of locale-related bugs indeed. I couldn't find this one though. Strange because what I am doing does not seem exotic at all. French, German, Portuguese and Spanish getlocale results are incorrect IMHO. Below is little check + output here in case it might be useful for others. This is with Python 3.4, 3.3 and 2.7 on Windows 7 64. from __future__ import print_function import locale import collections import pprint #https://msdn.microsoft.com/en-us/library/39cwe7zf%28v=vs.80%29.aspx languages = ("chinese czech danish dutch english finnish french german greek " "hungarian icelandic italian japanese korean norwegian polish " "portuguese russian slovak spanish swedish turkish") d = collections.defaultdict(list) t = collections.namedtuple("Locale", "lang setlocale getlocale") for language in languages.split(): sloc = locale.setlocale(locale.LC_ALL, language) gloc = locale.getlocale() record = t(language, sloc, gloc) if gloc[0][2] == "_": d["unix-like"].append(record) else: d["windows-like"].append(record) pprint.pprint(dict(d)) n:\>C:\Miniconda3\python.exe N:\temp\loc.py {'unix-like': [Locale(lang='french', setlocale='French_France.1252', getlocale=('fr_FR', 'cp1252')), Locale(lang='german', setlocale='German_Germany.1252', getlocale=('de_DE', 'cp1252')), Locale(lang='portuguese', setlocale='Portuguese_Brazil.1252', getlocale=('pt_BR', 'cp1252')), Locale(lang='spanish', setlocale='Spanish_Spain.1252', getlocale=('es_ES', 'cp1252'))], 'windows-like': [Locale(lang='chinese', setlocale="Chinese (Simplified)_People's Republic of China.936", getlocale=("Chinese (Simplified)_People's Republic of China", '936')), Locale(lang='czech', setlocale='Czech_Czech Republic.1250', getlocale=('Czech_Czech Republic', '1250')), Locale(lang='danish', setlocale='Danish_Denmark.1252', getlocale=('Danish_Denmark', '1252')), Locale(lang='dutch', setlocale='Dutch_Netherlands.1252', getlocale=('Dutch_Netherlands', '1252')), Locale(lang='english', setlocale='English_United States.1252', getlocale=('English_United States', '1252')), Locale(lang='finnish', setlocale='Finnish_Finland.1252', getlocale=('Finnish_Finland', '1252')), Locale(lang='greek', setlocale='Greek_Greece.1253', getlocale=('Greek_Greece', '1253')), Locale(lang='hungarian', setlocale='Hungarian_Hungary.1250', getlocale=('Hungarian_Hungary', '1250')), Locale(lang='icelandic', setlocale='Icelandic_Iceland.1252', getlocale=('Icelandic_Iceland', '1252')), Locale(lang='italian', setlocale='Italian_Italy.1252', getlocale=('Italian_Italy', '1252')), Locale(lang='japanese', setlocale='Japanese_Japan.932', getlocale=('Japanese_Japan', '932')), Locale(lang='korean', setlocale='Korean_Korea.949', getlocale=('Korean_Korea', '949')), Locale(lang='norwegian', setlocale='Norwegian (Bokmål)_Norway.1252', getlocale=('Norwegian (Bokmål)_Norway', '1252')), Locale(lang='polish', setlocale='Polish_Poland.1250', getlocale=('Polish_Poland', '1250')), Locale(lang='russian', setlocale='Russian_Russia.1251', getlocale=('Russian_Russia', '1251')), Locale(lang='slovak', setlocale='Slovak_Slovakia.1250', getlocale=('Slovak_Slovakia', '1250')), Locale(lang='swedish', setlocale='Swedish_Sweden.1252', getlocale=('Swedish_Sweden', '1252')), Locale(lang='turkish', setlocale='Turkish_Turkey.1254', getlocale=('Turkish_Turkey', '1254'))]} -- https://mail.python.org/mailman/listinfo/python-list