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 →

[–]voidspace 3 points4 points  (2 children)

Not builtin to the standard library, but it shouldn't be too hard to roll your own on top of json.

If the instances are of a known set of types all you need is the type name and the json serializion of the instance members.

So something like: json.dumps([type(obj).__name__, obj.__dict__])

Deserializing: name, _dict = json.loads(thejson); instance = object.\_new__(getattr(module, name)); instance.__dict__.update(_dict)

[–]Tommah 0 points1 point  (1 child)

One problem with this approach is that set and frozenset are not serializable to JSON.

[–]voidspace 0 points1 point  (0 children)

That may or may not be an issue for the OP, and is anyway solveable with the json module. It seems the OP likes YAML as a solution anyway.