为什么Python会忽略LC_ALL?

时间:2013-12-13 23:27:40

标签: python

[d33tah-pc][~] $ LC_ALL="pl_PL.UTF-8" date  
sob, 14 gru 2013, 00:26:48 CET
[d33tah-pc][~] $ LC_ALL="pl_PL.UTF-8" python
Python 2.7.5 (default, Nov 12 2013, 16:18:42) 
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.strftime("%c")
'Sat Dec 14 00:26:57 2013'
>>> import locale
>>> locale.setlocale(locale.LC_TIME, 'pl_PL.UTF-8')
'pl_PL.UTF-8'
>>> time.strftime("%c")
'sob, 14 gru 2013, 00:27:09'

为什么Python在这种情况下不使用系统的环境变量?

1 个答案:

答案 0 :(得分:3)

因为默认情况下永远不会使用它们。您必须显式启用区域设置支持。

locale.setlocale(locale.LC_TIME, '')