您好,登錄后才能下訂單哦!
import pickle
def sh(name):
print("hello,",name)
#序列化存儲(chǔ)
info={'key':'mode',
'lis':'koud',
'olo':234,
'func':sh
}
f=open("text.txt","wb")
print(pickle.dumps(info)) #pickle序列化以二進(jìn)制存儲(chǔ)
f.write(pickle.dumps(info))
pickle.dump(info,f) #優(yōu)化后的寫法效果完全相同
f.close()
import pickle #只有在python語(yǔ)言里用
def sh(name): #序列化整個(gè)函數(shù)
print("hello3,",name)
print("hello4,",name)
f=open("text.txt","rb") #pickle反序列化讀取的是二進(jìn)制數(shù)據(jù)
data=pickle.loads(f.read())
data=pickle.load(f) #優(yōu)化寫法效果完全相同
print(data"func")
import shelve,datetime
#a=shelve.open("new_year")
name=["alex","jack","tomo"]
info={"age":22,"job":"it","name":"alex"}
date=datetime.datetime.now()
a["name"]=name
a["indo"]=info
a["date"]=date
a.close()
import shelve,datetime
a=shelve.open("new_year")
print(a.get("indo"))
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。