From: Shashank Bapat (shashankbapat_at_[hidden])
Date: 2006-11-23 00:49:49
Both pickle and cPickle seem to have problem pickling boost wrapped enum
Pickle protocol used here is 2.
Problem is causes by enum.cpp. In there __name__ and __module__ are
intentionally set in certain way (which is different than how its done in
class.cpp). So I suppose there is a valid reason why its that way.
In that case the __reduce__ and __reduce_ex__ implementation for enum_
should take care of this so as to ensure proper pickling.
print "Lets pickle some boost enum:"
f = open("tmp1.txt", "w")
cPickle.dump( EnumTest.Color.red , f, cPickle.HIGHEST_PROTOCOL)
print "Why is EnumTest.Color.__name__ = '%s' and
\nEnumTest.Color.__module__= '%s' ?\n" % ( EnumTest.Color.__name__,
print "Lets hack it and try again:"
f = open("tmp2.txt", "w")
EnumTest.Color.__name__ = "Color"
EnumTest.Color.__module__ = "EnumTest"
l = (EnumTest.Color.red, EnumTest.Color.green, EnumTest.Color.blue)
for e in l:
cPickle.dump( e , f, cPickle.HIGHEST_PROTOCOL)
print "Unpickle Test:"
f = open("tmp2.txt", "r")
for e in l:
if e != cPickle.load(f):
raise "Load Failed"
Get free, personalized commercial-free online radio with MSN Radio powered
by Pandora http://radio.msn.com/?icid=T002MSN03A07001
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk