【转译】解决python3读取Python2存储的pickle文件

在python3.5处理在python2.7里面存储的序列化文件xxx.pkl会报错。

import pickle
picklefile=open('python2.pkl','rb')
data=pickle.load(picklefile)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 11: ordinal not in range(128)

解决办法:在pickle.load中加上encoding参数

data=pickle.load(picklefile,encoding='iso-8859-1')

 

【参考自】https://blog.csdn.net/accumulate_zhang/article/details/78597823

你可能感兴趣的:(python)