用於儲存和載入的函式實用程式
將資料儲存到檔案或從檔案儲存
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'