Skip to main content
gamedev.net
🔒 Locked

[Boost::Python] Pickling Enums

Started by Ezbez Jul 1, 2007 at 7:04 PM 0 replies 1.7k views
Original Post
Ezbez
Ezbez
I can't figure out how to pickle enums that I've defined in C++ then exported to Python with the boost::python enum_ class. I've asked on the C++-SIG at Python.org but no replies. Here's some code:
enum BlendType { NoBlend, Transparent, Additive };

BOOST_PYTHON_MODULE(Renderer)
{
    enum_<BlendType>("BlendType")
        .value("NoBlend",NoBlend)
        .value("Transparent",Transparent)
        .value("Additive",Additive)
    ;
}
In Python, one of my objects has a BlendType member. When I pickle that object, it gives me this error:
raise PicklingError(

pickle
.
PicklingError
: 
Can't pickle <class 'Renderer.BlendType'>: it's not found as __main__.Renderer.BlendType
I can't find any information on pickling enums, at all. I guess that since Python doesn't have that type, it's unusual to use it. If there's no way to resolve this, is there another way I can achieve the same thing?
Ezbez
Ezbez
Since even the simplest enum won't pickle for me, I've decided just to do a quick hack-around by using ints instead. Then I just defined some variables of the names of the enum values and with values of the corresponding ints. Then I changed my interface in C++ to accept ints and convert from there to the enum.

Eh, it works.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.