pickle,shelve,json模块

#json是把序列元素编译成所有语言都可以识别的格式
#pickle是把序列元素编译成Python语言都可以识别的格式
import pickle,shelve,json
res={'name':'liuwenwen',"age":28}
data=json.dumps(res)
print(json.loads(data))#{'name': 'liuwenwen', 'age': 28}json就是把字符串'改为"
print(data)
with open("my.log","w",encoding="gbk") as f:
json.dump(res,f)
with open("my.log","r",encoding="gbk") as f:
print(json.load(f))#{'name': 'liuwenwen', 'age': 28}

datte=[1,2,3]
a=pickle.dumps(datte)
print(pickle.loads(a))
my="iu"

with open("jk.txt","wb") as f:
pickle.dump(datte,f)
with open("jk.txt","rb") as f:
print(pickle.load(f))

a=shelve.open("a.txt")
a["name"]="liuwenwen"
a.close()
b=shelve.open("a.txt")
print(b["name"])
posted @ 2020-05-18 17:26  小文-520  阅读(146)  评论(0编辑  收藏  举报