标签:__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()
标签:__init__ 复杂 lan 通用 elf balance span ini open
原文地址:https://www.cnblogs.com/guowenshuang/p/10328177.html