【原】Python 用例:二进制写入和读取文件内容
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)
1.二进制文件,用NotePad++打开乱码
2.读取内容后,打印: