If pickled using pickle
then following snippet works. but if I have an object dumped using dill, dill.load
does not work because dill.load
does not accept any encoding
argument. is there any way to make this work using dill?
with open(‘py2pickle.p’,'rb') as f
data = pickle.load(f, encoding='latin1')
You did dill.dump
in python 2, and want do do a dill.load
in python 3. There are two issues:
there's no guarantee, regardless of what you are using for serialization that a pickle will work with any version of python other than the one you used (i.e. 3.7 vs 3.6 vs 2.7).
as you noted, currently dill
doesn't have an encoding argument on load
, so you may have to do some conversion before/after you dump
/load
the object (directly on the object itself).
Note that I will be adding more of the serialization option arguments to dump
and load
in the very near future (including the encoding
argument).
Update: dill
now has an encoding argument, as well as other arguments to aid pickle conversion from 2.x to 3.x.