test_decode = '测试'
print test_decode.decode('utf-8')
上面的简单代码可以在本地工作,但在pyspark中运行时无法工作,有谁知道为什么? pyspark中的错误如下:
Traceback (most recent call last):
File "/home/litaotao/Program/TrajectoryPrediction/src/cluster/Tool.py", line 62, in <module>
print test_decode.decode('utf-8')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
答案 0 :(得分:0)
添加代码:
# coding=utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')