3.3.5 Additional methods for emulation of sequence types

The following methods can be defined to further emulate sequence objects. Immutable sequences methods should only define __getslice__(); mutable sequences, should define all three three methods.

__getslice__ (self, i, j)
Called to implement evaluation of self[i:j]. The returned object should be of the same type as self. Note that missing i or j in the slice expression are replaced by zero or sys.maxint, respectively, and no further transformations on the indices is performed. The interpretation of negative indices and indices larger than the length of the sequence is up to the method.

__setslice__ (self, i, j, sequence)
Called to implement assignment to self[i:j]. Same notes for i and j as for __getslice__().

__delslice__ (self, i, j)
Called to implement deletion of self[i:j]. Same notes for i and j as for __getslice__().

Notice that these methods are only invoked when a single slice with a single colon is used. For slice operations involving extended slice notation, __getitem__(), __setitem__() or__delitem__() is called.


Send comments on this document to python-docs@python.org.


Banner.Novgorod.Ru