[C++-sig] Pickle python subclass of C++ interface

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Sat Jul 17 18:32:07 CEST 2010


I think all you need to do is add
  .enable_pickling()
to your Boost.Python wrapper and
  def __getinitargs__(self):
    return (x,y,z)
to your subclass.
You could also use __getstate__, __setstate__, but I'd try to work with
just __getinitargs__ first.

See also:

http://www.boost.org/doc/libs/1_43_0/libs/python/doc/v2/pickle.html


----- Original Message ----

From: John Reid <j.reid at mail.cryst.bbk.ac.uk>
To: cplusplus-sig at python.org
Sent: Sat, July 17, 2010 2:17:12 AM
Subject: [C++-sig] Pickle python subclass of C++ interface

Hi,

I'm using boost.python. I want to pickle some python subclasses of a C++ base. 
The C++ base does not have any state, it is just an interface. Is there an easy 
way to ask the python pickling machinery to ignore the C++ base? I'm not sure if 
I should use the boost.python pickling support or go directly down the route 
described at
http://docs.python.org/library/pickle.html#pickling-and-unpickling-extension-types


Thanks,
John.

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig at python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig



More information about the Cplusplus-sig mailing list