美文网首页
Python pickle

Python pickle

作者: 闫_锋 | 来源:发表于2018-07-17 16:55 被阅读8次
    #存储
    import pickle
    
    a_dict = {'da': 111, 2: [23,1,4], '23': {1:2,'d':'sad'}}
    
    # pickle a variable to a file
    file = open('pickle_example.pickle', 'wb')
    pickle.dump(a_dict, file)
    file.close()
    
    ########################
    #提取
    # reload a file to a variable
    with open('pickle_example.pickle', 'rb') as file:
        a_dict1 =pickle.load(file)
    
    print(a_dict1)
    

    相关文章

      网友评论

          本文标题:Python pickle

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