Hey All,
I am working on a project built on python 2.4 (It is an embedded python project, so I don't have a choice on the version of python used). Throughout the application, we use array.array
to store data.
Support for pickling array.array
objects was added to pickle
(and cPickle
) in 2.5. We have a viable workaround in 2.4 when using the pure python pickle class (we subclass Pickler/Unpickler to handle arrays) but this does not work with cPickle (we need this due to performance problems).
Any suggestions?
EDIT -- SOLUTION:
This is the final code that seems to be working (thanks for the suggestions):
# Add serialization for array objects
def array_unpickler(data):
return array.array(data[0], data[1:])
def array_pickler(arr):
return array_unpickler, ("%s%s" % (arr.typecode, arr.tostring()),)
copy_reg.pickle(array.ArrayType, array_pickler, array_unpickler)