您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python:在Windows终端中使用unicode,使用编码吗?

Python:在Windows终端中使用unicode,使用编码吗?

Unicode不是编码。您编码为字节字符串,然后解码为Unicode:

>>> '\x89'.decode('cp437')
u'\xeb'
>>> u'\xeb'.encode('cp437')
'\x89'
>>> u'\xeb'.encode('utf8')
'\xc3\xab'

Windows终端将旧版代码页用于DOS。对于美国Windows,它是:

>>> import sys
>>> sys.stdout.encoding
'cp437'

Windows应用程序使用Windows代码页。Python的IDLE将显示Windows编码:

>>> import sys
>>> sys.stdout.encoding
'cp1252'

您的结果可能会有所不同。

python 2022/1/1 18:33:05 有335人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶