Pickling array.array

Nicolas Fleury nid_oizo at yahoo.com_remove_the_
Fri May 14 13:54:57 EDT 2004


Nicolas Fleury wrote:
> I also added __getinitargs__(), but it is not called...

For those interested in the same problem, the only solution I've found 
is to encapsulate the array instead of derive from it.  It sucks a bit, 
since all methods need to be implemented to redirect to array.array, but 
at least it's working.  I'm still wondering how to do it with derivation...

Thx and regards,
Nicolas

import array as arr
class array:
     def __init__(self, typecode, initializer=None):
         self.arr = arr.array(typecode, initializer)
     def __getstate__(self):
         return {'buffer': self.arr.tostring(),
                 'typecode': self.arr.typecode}
     def __setstate__(self, dict):
         self.arr = arr.array(dict['typecode'])
         self.arr.fromstring(dict['buffer'])



More information about the Python-list mailing list