注意点
Python's pickle isperfectly cross-platform.
This is likely due to EOL (End-Of-Line)differences between Windows and Linux. Make sure to open your pickle files inbinary mode both when writing them and when reading them, using open()'s"wb" and "rb" modes respectively.
Note: Passing picklesbetween different versions of Python can cause trouble, so try to have the sameversion on both platforms.
协议
2个常量
4个函数
3个异常
2个类
example
一行代码读写pickle
# 保存pickle:
with open("result.pkl", "wb") as f:
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
# 读取pickle:
with open("result.pkl", "rb") as f:
data= pickle.load(f)
# 一行代码存pickle:
pickle.dump(data, open("result.pkl", "wb"), pickle.HIGHEST_PROTOCOL)
# 一行代码读pickle:
data=pickle.load(open("result.pkl", "rb"))
pickle跨平台
Python的pickle完全是跨平台的。
这可能是由于Windows和Linux之间的EOL(行尾)差异造成的。确保在写入和读取pickle文件时,分别使用open()的“wb”和“rb”模式以二进制模式打开它们。
注意:在不同版本的Python之间传递pickle可能会带来麻烦,因此请尝试在两个平台上使用相同的版本。