首页 > 代码库 > python pickle
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)
python pickle
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。