python pickle

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章

001--python全栈--基础知识--python安装

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python