2

tl;dr

How to get a parsed version of the pickle's data (one specifying, in a "readable" manner, what is needed to make the desired unpickled object)

motivation

How to use keep as much of the "no boilerplate" user-friendliness of pickle, while being able to deal with it's limitations?

The user-friendliness of pickle is proven by the fact that most take for granted the fact that one can save (almost) any custom object in one place, and load it somewhere else, until...

  • you don't have the necessary modules to create the unpickled objects
  • you changed one of the classes of one of those objects
  • you used a lambda (yes, I'm aware of dill)

So pickle is powerful, but brittle in the sense that it will break easily. It favors correctness over (implicit) flexibility, and that's probably a good thing.

But when more (even explicit) flexibility is needed, where should we turn? What are the best practices and tools around this effort? If I could get a "parsed" version of the pickle data (see tl;dr above), I can use it, and __setstate__ and __getstate__ to stretch pickle further. But perhaps there's already standard tools to take care of these problems?

thorwhalen
  • 1,920
  • 14
  • 26
  • Perhaps a duplicate of [Inspecting a pickle dump for dependencies](https://stackoverflow.com/a/64850705); the tool is `pickletools` and is part of the standard lib. – Martijn Pieters Feb 04 '21 at 16:38

0 Answers0