pickle,shelve,json 모듈

1005 단어
#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"])

좋은 웹페이지 즐겨찾기