File "run.py", line 37, in <module> print str1 UnicodeEncodeError: 'latin-1' codec can't encode characters in position 24-29: ordinal not in range(256)
運行時打印字符串,出現UnicodeEncodeError: 'latin-1' codec can't encode characters的錯誤,原始字符串應該為utf-8。
python -c "import sys; print sys.stdout.encoding" ISO-8859-1
打印系統編碼格式,顯示為ISO-8859-1。
這種情況應該為term編碼格式不匹配,應這樣打印
s = u"\u5149\u66dc\u65e5\u3067\u30e9\u30c6 \u30d4\u30af\u30b7\u30fc\u4e71\u7372\u884c\u304d\u307e\u3059 \u5e0c\u671b\u8005\u52df\u96c6\u4e2d\u3067\u3059\uff3e\uff3e" print s.encode('utf-8') #Output: 光曜日でラテ ピクシー亂獲行きます 希望者募集中です^^