>>> import safepickle
>>> import pickle
>>>
>>> data = {None: True}
>>>
>>> with open('unsafe.dat', 'wb') as f:
... pickle.dump(data, f)
...
>>> with open('safe.dat', 'w+') as f:
... safepickle.dump(data, f)
...
>>> with open('unsafe.dat', 'rb') as f:
... unsafe=pickle.load(f)
...
>>> with open('safe.dat', 'r') as f:
... safe=safepickle.load(f)
...
>>> safe == data
False
>>> unsafe == data
True
>>> safe
{'null': True}
>>>
The behavior of safepickle is not the same as pickle when saving Nonetype, what you load is not what you saved. In this case the key None has been changed to "null" when using safepickle.
The behavior of safepickle is not the same as pickle when saving Nonetype, what you load is not what you saved. In this case the key
None
has been changed to"null"
when using safepickle.