问题描述
当使用 pickle.dump()
将类对象写入pickle文件时,
with open(".../XX.pickle", "w") as f:
pickle.dump(ClassObject, f)
f.close()
出现了错误:
TypeError: write() argument must be str, not bytes
错误原因
pickle默认存储方式是二进制
解决方法
访问模式: w
改为 wb
with open(".../XX.pickle", "wb") as f:
pickle.dump(ClassObject, f)
f.close()