码迷,mamicode.com
首页 > Web开发 > 详细

pickle_json 序列化反序列化

时间:2019-01-28 00:44:53      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:__init__   复杂   lan   通用   elf   balance   span   ini   open   

JSON 通用,只能识别 列表,字典等简单数据

PICKLE仅PYTHON适用,可序列化复杂类似对象等

使用举例:

import json,pickle

class Account:
def __init__(self,total,pay):
self.total = total
self.pay = pay
def Pay(self):
self.balance = self.total - self.pay # (余额)
return (self.balance)

def Record():
f = open("result_name",‘rb‘)
balance = pickle.load(f)
if balance:
print(balance)
# total = request.POST.get("total")
# pay = request.POST.get("pay")
total = balance
pay = 30
rc = Account(total,pay)
result = rc.Pay()
f = open("result_name","wb")
pickle.dump(result,f)
f.close()
print(result)
Record()

 

pickle_json 序列化反序列化

标签:__init__   复杂   lan   通用   elf   balance   span   ini   open   

原文地址:https://www.cnblogs.com/guowenshuang/p/10328177.html

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