我很好奇python源代码如何设置Py_FileSystemDefaultEncoding的值。我收到了一件奇怪的事。在
因为python doc关于sys.getfilesystemcoding()说:
On Unix, the encoding is the user’s preference according to the result of nl_langinfo(CODESET), or None if the nl_langinfo(CODESET) failed.
我使用python2.7.6
```
>>>import sys
>>>sys.getfilesystemencoding()
>>>'UTF-8'
>>>import locale
>>>locale.nl_langinfo(locale.CODESET)
>>>'ANSI_X3.4-1968'
```
这里有一个问题:为什么getFileSystemCoding()的值与locale.nl\u landinfo()因为doc说getfilesystemencoding()是从locale.nl\u landinfo(). 在
以下是我的终端中的locale命令输出:
^{pr2}$
摘要:
sys.getfilesystemencoding()
的行为与文档中的相同。这种混淆是由于setlocale(LC_CTYPE, "")
(用户的首选项)和默认的C语言环境之间的差异造成的。在脚本始终以默认的C语言环境开头:
但是
^{pr2}$getfilesystemencoding()
使用用户的区域设置:空字符串作为区域设置名称selects a locale based on the user choice of the appropriate environment variables。在
Python 2.7的源代码中有两个位置:
Py_FileSystemDefaultEncoding
setlocale(LC_CTYPE, "")
是在nl_langinfo(CODESET)
之前调用的,它在setlocale(LC_CTYPE, saved_locale)
之后恢复。在要找到这些地方:
clone Python 2.7 source code:
在编辑器中搜索
Py_FileSystemDefaultEncoding *=
regex,例如:在Emacs中:}继续搜索。
M-x tags-search RET Py_FileSystemDefaultEncoding *= RET
和{相关问题 更多 >
编程相关推荐