slice object unpickable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sebastien de Menten

    slice object unpickable

    Hi,

    I wonder why the slice object is not pickable via pickle or cPickle.
    E.g.:

    import pickle
    pickle.dumps(sl ice(0,4))

    leads to

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib/python2.3/pickle.py", line 1386, in dumps
    Pickler(file, protocol, bin).dump(obj)
    File "/usr/lib/python2.3/pickle.py", line 231, in dump
    self.save(obj)
    File "/usr/lib/python2.3/pickle.py", line 313, in save
    rv = reduce(self.pro to)
    File "/usr/lib/python2.3/copy_reg.py", line 69, in _reduce_ex
    raise TypeError, "can't pickle %s objects" % base.__name__
    TypeError: can't pickle slice objects

    Is it an omission ? Am I missing something non trivial that would
    impede slices to be pickable ?

    My main goal is to pickle an object with some slices as attributes. As
    my object is quite simple, I would like to enjoy the automatic pickle
    system (i.e. not rewrite a __getstate__, __setstate__, etc).
    Is there an easy workaround to the "unpickableness " of slices ? I
    tried subclassing slices but it is not allowed.

    Thanks for your help.

    Seb
Working...