python 来自http://stackoverflow.com/questions/19201290/how-to-save-a-使用pickle加载和保存对象的示例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 来自http://stackoverflow.com/questions/19201290/how-to-save-a-使用pickle加载和保存对象的示例相关的知识,希望对你有一定的参考价值。

def save_obj(obj, name ):
    with open('obj/'+ name + '.pkl', 'wb') as f:
        pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)

def load_obj(name ):
    with open('obj/' + name + '.pkl', 'rb') as f:
        return pickle.load(f)
import _pickle as pickle

def save_obj(obj, name):
    with open(name, 'wb') as f:
        pickle.dump(obj, f)

def load_obj(name ):
    with open(name, 'rb') as f:
        return pickle.load(f)

# fpath = 'data.pkl'

以上是关于python 来自http://stackoverflow.com/questions/19201290/how-to-save-a-使用pickle加载和保存对象的示例的主要内容,如果未能解决你的问题,请参考以下文章

python 来自Python的Git pull

python 来自Python的os文件系统

一封来自“Python”的信

来自 Black Hat Python 书的 Python 嗅探

“路径 python3(来自 --python=python3)不存在”错误

python Python装饰模板(来自“Head First Python ed.2”)