import pickle
class Cat:
'''
The object of cat
'''
foot = "foot"
head = "head"
body = "body"
def open_pickle_file(file_path):
'''
Open the file of bin
:param file_path: path of file
:return:
'''
with open(file_path, 'rb') as f:
data = pickle.load(f)
print(data[0].head)
print(data[0].body)
print(data[0].foot)
return 0
def save_pickle_file(data, file_path):
'''
Save the file of data
:param data: The data of input
:param file_path: The path of file
:return:
'''
with open(file_path, 'wb') as f:
pickle.dump(data, f)
if __name__ == '__main__':
file_path = 'D:/tmp.pk'
data = list()
data.append(Cat())
data.append(Cat())
save_pickle_file(data, file_path)
open_pickle_file(file_path)