Raspberry Pi上的问题解码utf-8

问题描述 投票:1回答:1

我在覆盆子pi上解码utf-8时遇到问题...在我的计算机上也可以使用相同的代码。但不适用于覆盆子。有任何线索吗?

在我的笔记本电脑上(预期输出):

Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> b'\xc3\xa9'.decode('utf-8')
'é'

在raspberrypi上(意外输出):

Python 3.5.4 (default, Sep  5 2017, 18:32:10) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> b'\xc3\xa9'.decode('utf-8')
'�'
python linux raspberry-pi python-3.5
1个回答
2
投票

区别在于两个系统上的语言环境设置。您可以通过以下方式在python中进行检查:

>>> import locale
>>> locale.getpreferredencoding()
UTF-8

您的一个系统应报告UTF-8编码,而另一个则不报告(大概是ISO-8859-1)。在Linux上,检查locale命令的输出以检查是否有差异,然后调整区域设置以匹配(通过localectlupdate-locale或发行版提供的任何内容)。

© www.soinside.com 2019 - 2024. All rights reserved.