Thursday, 25 October 2018

Pickling dict in Python

Can I expect the string representation of the same pickled dict to be consistent across different machines/runs for the same Python version? In the scope of one run on the same machine?

e.g.

# Python 2.7

from pickle import dumps
pickle = lambda d: dumps(d)
initial = pickle({'a': 1, 'b': 2})
for _ in xrange(1000**2):
    assert pickle({'a': 1, 'b': 2}) == initial

Does it depend on the actual structure of my dict object (nested values etc.)?

UPD: The thing is - I can't actually make the code above fail in the scope of one run (Python 2.7) no matter how my dict object looks like (what keys/values etc.)



from Pickling dict in Python

No comments:

Post a Comment