标签:EAP pre lan lex code lang fifo pen 模块
dump 写入文件
dumps 生成序列化的字符串
loads 把序列号的字符串反向解析
load 从字符串加载
import pickle
d = {
"name":"chen",
"role":"police",
"blood": 76,
"weapon":"ak47"
}
alive_palyers = [‘alex‘,‘jack‘,‘rain‘]
print(pickle.dumps(d)) #序列号
d_dump = pickle.dumps(d) print(pickle.dumps(d)) #序列号
print(pickle.loads(d_dump)) # 反序列号 加载
f = open("game.pkl",‘wb‘) # 写入二进制数据
pickle.dump(d,f)
pickle.dump(alive_palyers,f)
# dump 写入文件
# dumps 生成序列化的字符串
--------------------------------------------------------------------
b‘\x80\x04\x95=\x00\x00\x00\x00\x00\x00\x00}\x94(\x8c\x04name\x94\x8c\x04chen\x94\x8c\x04role\x94\x8c\x06police\x94\x8c\x05blood\x94KL\x8c\x06weapon\x94\x8c\x04ak47\x94u.‘
{‘name‘: ‘chen‘, ‘role‘: ‘police‘, ‘blood‘: 76, ‘weapon‘: ‘ak47‘}
import pickle
f = open("game.pkl",‘rb‘)
print(pickle.load(f)) # first in first out FIFO 先进先出
print(pickle.load(f))
--------------------------------------
{‘name‘: ‘chen‘, ‘role‘: ‘police‘, ‘blood‘: 76, ‘weapon‘: ‘ak47‘}
[‘alex‘, ‘jack‘, ‘rain‘]
标签:EAP pre lan lex code lang fifo pen 模块
原文地址:https://www.cnblogs.com/chenfei2928/p/12777528.html