#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"])
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步