Assume that I have a pickle dump - either as a file or just as a string - how can I determine the protocol that was used to create the pickle dump automatically?
And if so, do I need to read the entire dump to figure out the protocol or can this be achieved in O(1)? By O(1) I think about some header information at the beginning of the pickle string or file whose read out does not require processing the whole dump.
Thanks a lot!
EDIT: I have an update on this, apparently the answer given below does not always work under python 3.4. If I simply pickle the value True
with protocol 1, sometimes I can only recover protocol 0 :-/