作者:手机用户2702933093 | 来源:互联网 | 2023-05-16 16:10
阿里的pai平台是python2.x,在python3下的代码经常会有问题。比如python3的str可以用来编码,python的str只是转为字符串,需要用str(1).encode(utf-8
阿里的pai平台是 python2.x,在python3下的代码经常会有问题。
比如python3的str可以用来编码,python的str只是转为字符串,需要用str(1).encode('utf-8').decode('utf-8')这样。
在python3中序列化Python2不能识别,这时只要这样序列化:
python3:
with open(pwd,'wb') as f:
pickle.dump(x,f,protocol = 2)
这样序列化后的x在Python2里面就能读取
python2:
with open(pwd,'rb') as f:
pickle.dump(f)