针对于数据量比较大的列表、字典,可以采用将其加工为数据包来调用,减小文件大小
#列表
#存储
list1 = [123,'xiaopingguo',54,[90,78]]
list_file = open('list1.pickle','wb')
pickle.dump(list1,list_file)
list_file.close()
#读取
list_file = open('list1.pickle','rb')
list2 = pickle.load(list_file)
print(list2)
#字典
#存储
list3 = {'12': 123, '23': 'xiaopingguo', '34': 54, '45': [90, 78]}
list3_file = open('list3.pickle', 'wb')
pickle.dump(list3, list3_file)
list3_file.close()
# # 读取
list3_file = open('list3.pickle', 'rb')
list3 = pickle.load(list3_file)
print(list3)
print(list3['23']