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"u5149u66dcu65e5u3067u30e9u30c6 u30d4u30afu30b7u30fcu4e71u7372u884cu304du307eu3059 u5e0cu671bu8005u52dfu96c6u4e2du3067u3059uff3euff3e" print s.encode('utf-8') #Output: 光曜日でラテ ピクシー乱獲行きます 希望者募集中です^^