2013-10-15 45 views
2

什麼是在Python 2.x上獲取當前Windows(或OSX)語言環境ID的方法。我想獲得一個int(或str),它告訴OS中哪種語言是活動的。Python:獲取OS語言

可能不使用WinAPI?

回答

9

這是與Python 2.6中的locale模塊相關的文檔。

更具體地講,這裏是如何讓你的系統的語言環境的例子(從上面的鏈接):

import locale 
loc = locale.getlocale() # get current locale 
locale.getdefaultlocale() # Tries to determine the default locale settings and returns them as a tuple of the form (language code, encoding); e.g, ('en_US', 'UTF-8'). 
+0

這是很好的。不過,我在2.7.5版本中獲得(無,無)。 [這個bug](http://bugs.python.org/issue6203)?它雖然封閉。 – KobeJohn

+1

你可以嘗試:'locale.getdefaultlocale()'輸出給我:'('en_US','UTF-8')' –

+0

很好。我應該從文檔中鏈接的那一行上面讀取。感謝您將它添加到答案中。 – KobeJohn