[C++-sig] Pickling Enums

Tom Brooks tbrooks.mail at gmail.com
Sat Jun 30 12:48:36 CEST 2007


Hello,

I've searched the web, and this question has come up a couple of times, but
I haven't been able to find an answer. My problem is that I get an error
when trying to pickle an enum that's been exposed with Boost::Python.

enum BlendType { NoBlend, Transparent, Additive };

BOOST_PYTHON_MODULE(Renderer)
{
    enum_<BlendType>("BlendType")
        .value("NoBlend",NoBlend)
        .value("Transparent",Transparent)
        .value("Additive",Additive)
        .export_values()
    ;
}

The error is very long, but here's the end part of it:

...
save(element)

  File "C:\Python24\lib\pickle.py", line 293, in save


f(self, obj) # Call unbound method with explicit self

  File "C:\Python24\lib\pickle.py", line 760, in save_global


raise PicklingError(

pickle
.
PicklingError
:
Can't pickle <class 'Renderer.BlendType'>: it's not found as
__main__.Renderer.BlendType



If it matters, this pickling happens when I pickle another class. I have no
idea where to start, since you can't def_pickle or even .def for an enum_.
How do I go about doing this?

Thanks in advanced
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070630/68be8dc2/attachment.htm>


More information about the Cplusplus-sig mailing list