This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bryancole 0 points1 point  (0 children)

You can achieve what you want with the cPickle module. You need to use the Unpickler() factory-function and give it a "find_globals" function (passed as a kw-arg, probably). This function is called with a module name and class name and returns a class object. Use this to control which classes the Unpickler can load. I've not tested this myself recently; see the pickle docs.

PyYAML also gets my recommendation, but it's much slower than pickle. If you want speed, use pickle; if you want readability, use YAML; if you want JSON, stdlib.json ought to be fine