在开发一个旨在运行Debian Jessie(armhf端口)的Raspberry Pi 2上运行的Python应用程序时,我发现我的amd64端口和RPi之间的unicode处理存在差异:
与Debian Jessie的Raspberry Pi 2(模型B)
Linux echo 3.18.0-trunk-rpi2#1 SMP PREEMPT Debian 3.18.5-1~exp1.co1(2015-02-02)armv7l GNU / Linux
user@echo:~$ python3
Python 3.4.2 (default, Oct 8 2014, 14:38:51)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import binascii as ba
>>> b="414243FC"
>>> u=ba.unhexlify(b)
>>> u
b'ABC\xfc'
>>> s=u.decode('latin-1')
>>> s
'ABC\xfc'
>>> print(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 3: ordinal not in range(128)
具有相同Python版本的amd64虚拟框中的相同代码 Linux jessie-vbox 3.16.0-4-amd64#1 SMP Debian 3.16.7-ckt20-1 + deb8u1(2015-12-14)x86_64 GNU / Linux
user@jessie-vbox:~$ python3
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import binascii as ba
>>> b="414243FC"
>>> u=ba.unhexlify(b)
>>> u
b'ABC\xfc'
>>> s=u.decode('latin-1')
>>> s
'ABCü'
>>> print(s)
ABCü
>>>
我错过了什么或这是一个错误吗? Debian bug还是Python bug?
非常感谢你的帮助!
答案 0 :(得分:0)
由于我不需要语言环境支持(并且没有配置任何其他语言环境),我将LANG设置为“C.UTF-8”。