码迷,mamicode.com
首页 > 编程语言 > 详细

python pickle

时间:2017-07-23 09:57:52      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:pickle   auth   utf-8   exce   test   pen   import   cpi   read   

#!/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

标签:pickle   auth   utf-8   exce   test   pen   import   cpi   read   

原文地址:http://www.cnblogs.com/vickey-wu/p/7223389.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!