# filename:picklng.py
import pickle as p#import pickle as pshoplistfile = 'shoplist.data'#the name of the file where we will store the objectshoplist = ['apple','mango','carrot']#write to the filef=open(shoplistfile,'wb') #wb, 开启二进制,否则会报错TypeError: must be str, not bytesp.dump(shoplist,f) #dump the object to a filef.close()del shoplist # remove the shoplist#read from the storagef=open(shoplistfile,"rb") #如果缺少rb,则会报错:TypeError: 'str' does not support the buffer interfacestoredlist=p.load(f)print(storedlist)