用于保存和加载的函数实用程序
将数据保存到文件或从文件保存
import pickle
def save(filename,object):
file=open(filename,'wb')
pickle.dump(object,file)
file.close()
def load(filename):
file=open(filename,'rb')
object=pickle.load(file)
file.close()
return object
>>>list_object=[1,1,2,3,5,8,'a','e','i','o','u']
>>>save(list_file,list_object)
>>>new_list=load(list_file)
>>>new_list
[1, 1, 2, 3, 5, 8, 'a', 'e', 'i', 'o', 'u'