Python3, __slots__ and serialization

Eric Jacoboni eric.jacoboni at gmail.com
Sat Feb 8 13:06:31 EST 2014


Hi,

Say i want create a class with a __slots__ tuple in order to prevent
creation of new attributes from outside the class.

Say i want to serialize instances of this class... With pickle, all is
ok : i can dump an object to a file, then reload it.

With PyYAML, i can dump an object to a file, but trying to reload it fails.

If i comment out the __slots__ tuple, all is fine but, then, the class
is "open"... Is there some magic to have both a __slots__ tuple and a
working yaml.load() ?



More information about the Python-list mailing list