pah8J
pah8J

Reputation: 867

Is the file dumped by pickle strictly limited by version and implementation of Python?

When I preserve the object to file with pickle, is the file will be expired when I update the python interpreter(for example from 3.6.4 to 3.7.0r1) or change the implementation of python(for example from cpython to pypy)?

If it does, is there a range of compatibility to allow upgrade of platform? Or is there a tools to convert these dumped file to adapt new platform?

Upvotes: 2

Views: 711

Answers (2)

Mattwmaster58
Mattwmaster58

Reputation: 2576

No, it doesn't matter. The only issue would be going from 3.x to 2.x, as noted in pickle.py. The latest pickle can read all file formats that were written in one of the listed versions (note that 1.0 was the original pickle implementation):

  • 1.0
  • 1.1
  • 1.2
  • 1.3
  • 2.0
  • 3.0
  • 4.0

Changing between python implementations such as IronPython or Jython shouldn't matter as long as they properly implement standard library modules which almost all do.

Upvotes: 2

Grant David Bachman
Grant David Bachman

Reputation: 2248

If you're just pickling across versions of python 3, then you won't run into any problems with the default protocol. However, if you require the pickle file to be read by python 2, then you can change the pickle version to 0 during the dump, which can be read by python 2 and python 3.

I recommend reading the docs as it has much more on the topic: https://docs.python.org/3/library/pickle.html

Upvotes: 2

Related Questions