有什么区别系统标准输出编码, locale.getpreferredencoding(),和sys.getdefaultencoding()?

2024-05-28 11:17:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,对这种编码方式很困惑。到目前为止,我已经读过以下类型的“编码”:

import sys
import locale

print (sys.stdout.encoding)
print (locale.getpreferredencoding())
print (sys.getdefaultencoding())

输出:

^{pr2}$

有什么区别?在


Tags: import类型编码stdoutsyslocaleencodingprint
1条回答
网友
1楼 · 发布于 2024-05-28 11:17:30

简单地说,编码就是存储数据的方式记忆。那个不同的方式,允许更多的字符和信息。如需深入解释,欢迎阅读http://kunststube.net/encoding/,或Wikipedia

在python中,可以通过物理调用编码类型或使用the coding function中的任何一种来更改存储内容的方式。在

对于python3.x环境,sys.stdout.encoding和{}之间没有区别。它们都使用8位代码单元(最标准)。而首选的编码locale.getpreferredencoding()cp1252)是latin1的windows版本。在

请注意,如果您希望获得任何方法/函数的快速反馈,可以始终使用help命令。在

示例:

>>> import locale
>>> help(locale.getpreferredencoding)

输出:

^{pr2}$

相关问题 更多 >