![](/img/trans.png)
[英]Lambda in return statement gives two outputs but only one if print is not used
[英]Simple print statement gives UnicodeEncodeError on one of two RPI
當我將程序從一個RPI復制到另一個RPI時,突然在日志文件中出現了很多錯誤。 我把問題縮小到與丹麥字母lettersØÅ有關的問題。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
print("ABC æøå ÆØÅ") #Danish characters
在我的一個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)
在另外兩個上,我運行得很好。
Python版本Python 3.5.3使用raspi-config檢查了丹麥語的本地化。
在執行python命令之前,將以下幾行添加到您的終端。
export PYTHONIOENCODING=utf-8
現在在同一終端上運行python test.py
。
或者,您可以在test.py
文件頂部添加以下行
import sys
sys.setdefaultencoding('utf-8')
有關更多詳細信息,請檢查以下問題,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.