📜  如何将对象存储在文件中python代码示例

📅  最后修改于: 2022-03-11 14:45:22.577000             🧑  作者: Mango

代码示例2
import pickle

myobj = MyObj()

# save obj to file
with open('myfile.pkl', 'wb') as f:
    pickle.dump(myobj, f)

# read obj from file
with open('myfile.pkl', 'wb') as f:
    obj = pickle.load(f)