美文网首页
数据持久存储:pickle模块的基本使用

数据持久存储:pickle模块的基本使用

作者: 望月成三人 | 来源:发表于2016-11-23 12:41 被阅读18次
import pickle

def save(obj):
    obj = {"a": 1, "b": 2, "c": 3}
    # 将 obj 持久化保存到文件 tmp.txt 中
    with open('data.pickle', 'w') as f:
        pickle.dump(obj, f)

def read():
    # 将 obj 持久化保存到文件 tmp.txt 中
    with open('data.pickle', 'r') as f:
        return pickle.load(f)

相关文章

网友评论

      本文标题:数据持久存储:pickle模块的基本使用

      本文链接:https://www.haomeiwen.com/subject/dhqvpttx.html