[C++-sig] Pickle an enum from c++
Matthew Scouten (TT)
Matthew.Scouten at tradingtechnologies.com
Mon Dec 8 18:16:00 CET 2008
>From the lack of response I assume that no one has any clever ideas to
make an enum pickleable. Thank you to anyone who put thought into this.
If I come up anything that works, I will let the group know.
From: Matthew Scouten (TT)
Sent: Tuesday, December 02, 2008 2:24 PM
To: Development of Python/C++ integration
Subject: Pickle an enum from c++
I have an enum in my c++ library. In fact I have a crap load of them.
169 to be exact.
I need them to be pickle-able. The enum_ object does not have a
.def_pickle function, so I cannot use the pickle suite. I tried to just
up and pickle it but that does not work either.
enum box {cardboard, cereal, toy};
BOOST_PYTHON_MODULE(busybox)
{
enum_<box>("box")
.value("cardboard",cardboard )
.value("cereal",cereal )
.value("toy", toy);
}
C:\Documents and Settings\mscouten>cd C:\tt-dev\manticore\
C:\tt-dev\manticore>call setpath.bat
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle, busybox
>>>
>>> b = busybox.box.toy
>>>
>>> bs = pickle.dumps(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python25\lib\pickle.py", line 1366, in dumps
Pickler(file, protocol).dump(obj)
File "C:\Python25\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Python25\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python25\lib\pickle.py", line 401, in save_reduce
save(args)
File "C:\Python25\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python25\lib\pickle.py", line 562, in save_tuple
save(element)
File "C:\Python25\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python25\lib\pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <class '__main__.busybox.box'>: it's
not found as __main__.busybox.box
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20081208/d2ff7e4e/attachment.htm>
More information about the Cplusplus-sig
mailing list