How do I write a representer for PyYAML?
问题 I want to have a custom function that serializes arbitrary python objects, like how the json.dump function has an optional arg called 'default', that should be a function that the json dumper will call if the object is not json serializable. I simply want to do the equivalent of this from the json package. json.dump(tests_dump, file('somefile', 'w+'), default = lambda x: x.__dict__) It looks like I need to write yaml.add_representer, from the PyYAML docs, but it really isn't clear how to do