Home > Backend Development > Python Tutorial > python3序列化与反序列化用法实例

python3序列化与反序列化用法实例

WBOY
Release: 2016-06-10 15:11:35
Original
1464 people have browsed it

本文实例讲述了python3序列化与反序列化用法。分享给大家供大家参考。具体如下:

#coding=utf-8
import pickle
aa={}
aa["title"]="我是好人"
aa["num"]=2
t=pickle.dumps(aa)#序列化这个字典
print(t)
f=pickle.loads(t)#反序列化,还原原来的状态
print(f)

Copy after login

运行结果如下:

(dp0
S'num'
p1
I2
sS'title'
p2
S'\xe6\x88\x91\xe6\x98\xaf\xe5\xa5\xbd\xe4\xba\xba'
p3
s.
{'num': 2, 'title': '\xe6\x88\x91\xe6\x98\xaf\xe5\xa5\xbd\xe4\xba\xba'}

Copy after login

希望本文所述对大家的Python程序设计有所帮助。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template