zoukankan      html  css  js  c++  java
  • python pickle

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    # @date: 2017/7/22 23:41
    # @name: Python_learn
    # @author:vickey-wu

    import os
    import json
    try:
    import cPickle as pickle
    except:
    import pickle

    test_dict = {"name":"vickey","age":18}
    test_dict2 = dict(name = "vickey", age = 18)

    #serialization a dict
    dump_write = open("dump.txt","wb")
    # pickle.dump(test_dict,dump_write)
    test_dict_write = pickle.dump(test_dict,dump_write)
    dump_write.close()

    #deserialization a dict to dict
    dump_read = open("dump.txt","rb")
    test_dict_read = pickle.load(dump_read)
    print test_dict_read

    #serialization to json str
    json_serial = json.dumps(test_dict)

    #deserialization json str to dict
    json_deserial = json.loads(json_serial)
    print json_serial
    print json_deserial
    print type(json_serial),type(json_deserial),type(test_dict_write),type(test_dict_read)
  • 相关阅读:
    通过dockerfile制作nginx镜像
    docker存储卷
    docker容器网络配置
    状态模式
    抽象工厂模式
    观察者模式
    建造者模式
    外观模式
    模板方法模式
    原型模式
  • 原文地址:https://www.cnblogs.com/vickey-wu/p/7223389.html
Copyright © 2011-2022 走看看