Python中二进制文件的读与写
2018-09-18 本文已影响0人
薄荷糖的小窝
import pickle as p
shoplistfile='shoplist.data'
shoplist=['apple','carrot']
# because the dump operation is using binary, so 'b' is needed.
# also for read file.
f=open(shoplistfile,'wb')
p.dump(shoplist,f)
f.close
del shoplist
f=open(shoplistfile,'rb')
storedlist=p.load(f)
print(storedlist)