[C++-sig] Problem with pickling returning a boost::python::dict object

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Fri Jan 23 18:53:30 CET 2004


--- Pierre Barbier de Reuille <pierre.barbier at cirad.fr> wrote:
> At least, I must say the pickling support is a great feature !!

Thanks!

>      save[ "_vertices_" ] = c.getVertices();
>      save[ "_edges_" ] = c.getEdges();
>      save[ "_positions_" ] = c.pos_map;
>      save[ "_cells_" ] = c.cell_map;
>      save[ "_colors_" ] = c.color_map;

It would worry me to clutter the __dict__ with temporary attributes.
What if someone who is not aware of the implementation details of
your pickle support uses your class as a base class and defines
attributes _vertices_ etc.? It will be very hard for your user
to track down what is going wrong. It is much safer to put the
attributes in a new dictionary and to return a tuple with the
unmodified __dict__ and the additional dictionary with the state.
I think all you need to do this is two extra lines of code
(something like dict save; make_tuple(object_dict, save)).

Ralf



__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/




More information about the Cplusplus-sig mailing list