[英]Simple print statement gives UnicodeEncodeError on one of two RPI
When I copied my program from one RPI to another I suddenly got a lot of errors in the log file. 当我将程序从一个RPI复制到另一个RPI时,突然在日志文件中出现了很多错误。 I have narrowed the problem down to a thing related to danish letters ÆØÅ.
我把问题缩小到与丹麦字母lettersØÅ有关的问题。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
print("ABC æøå ÆØÅ") #Danish characters
On One of my RasberryPies it gives this error. 在我的一个RasberryPies上,出现此错误。
Traceback (most recent call last):File "test.py", line 5, in <module>
print("ABC \xe6\xf8\xe5 \xc6\xd8\xc5")
UnicodeEncodeError: 'ascii' codec can't encode characters in position 4-6: ordinal not in range(128)
On the two others i runs perfectly. 在另外两个上,我运行得很好。
Python version Python 3.5.3 Checked danish localization with raspi-config. Python版本Python 3.5.3使用raspi-config检查了丹麦语的本地化。
Before execute python command, add below lines to your terminal. 在执行python命令之前,将以下几行添加到您的终端。
export PYTHONIOENCODING=utf-8
Now run python test.py
in the same terminal. 现在在同一终端上运行
python test.py
。
Or you can add below lines in top of your test.py
file 或者,您可以在
test.py
文件顶部添加以下行
import sys
sys.setdefaultencoding('utf-8')
For more details, please check following question, 有关更多详细信息,请检查以下问题,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.