dill alternative to pickle

Whilst pickle is rather a defact standard - it has it's limitations (try saving Ordered Dictionaries). However there is also Dill

Easy install

pip install dill

Below is an exampe of usage


from collections import OrderedDict from pprint import pprint import pickle import dill

data=OrderedDict() data[0]={"Name":"Bob","Id":1} data[1]={"Name":" المتقين.","Id":3} data[2]={"Name":"Zob","Id":6}

pickle._dump(data,open("data.p","wb"),protocol=3) pprint(data)

Lets get the Data back

new_data=pickle.load(open("data.p","rb")) print(type(new_data)) pprint(new_data)

stored = dill.dumps(data) junk=1

import dill with open('company_dill.pkl', 'wb') as f: dill.dump(data, f) dill.dump(new_data, f) dill.dump(data.f)

with open('company_dill.pkl', 'rb') as f: data3 = dill.load(f) data4 = dill.load(f)

print(type(data3)) print(type(data4)) ``` ?