新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:python字典類型的數(shù)據(jù)怎么保存
在使用python編程過(guò)程中,我們往往需要借助字典來(lái)提高編程效率。同時(shí)為了調(diào)試方便,我們希望將某些變量保存為中間文件。

例如,在協(xié)同過(guò)濾算法中,相似性的訓(xùn)練結(jié)果可以保存為中間文件,方便調(diào)試。python對(duì)字典的保存與讀取可以借助于json方便
的實(shí)現(xiàn)
#保存
dict_name = {1:{1:2,3:4},2:{3:4,4:5}}
f = open('temp.txt','w')
f.write(str(dict_name))
f.close()
#讀取
f = open('temp.txt','r')
a = f.read()
dict_name = eval(a)
f.close()更多技術(shù)請(qǐng)關(guān)注Python視頻教程。
標(biāo)題名稱:創(chuàng)新互聯(lián)Python教程:python字典類型的數(shù)據(jù)怎么保存
鏈接地址:http://www.dlmjj.cn/article/dpdhiog.html


咨詢
建站咨詢
