1. 程式人生 > >python 中cPickle學習二

python 中cPickle學習二

ins watermark print basis f11 account src int count

寫入:

import cPickle as p
shoplistfile = ‘data.data‘
shoplist = [‘meili‘,[‘current_account‘,[100000,1222],‘basis_account‘,[5555555,888]],
            ‘qinshan‘,[‘current_account‘,[1089000,12292],‘basis_account‘,[55555955,888]],
            ‘jiayou‘,[‘current_account‘,[10000,12292],‘basis_account‘,[55555955,888]]
            ]
animallist=[‘hippo‘,‘rabbit‘,‘apple‘, ‘mango‘, ‘carrot‘]
f = file(shoplistfile, ‘w‘)
p.dump(shoplist,f,True)
p.dump(animallist,f,True)
f.close()

技術分享圖片

讀取:

f = file(shoplistfile)
storedlist = p.load(f)
animallist= p.load(f)

print storedlist
print animallist

結果:
技術分享圖片

python 中cPickle學習二