How to make slicing and other methods interact?

Michael Davidson mdavids+py at
Mon Jun 2 23:49:32 CEST 2003

On Mon, 02  2003, Tim Churches (tchur at wrote:
> What is the general pattern for making methods interact? For example, I

Try this change:

Instead of

> 	def __getslice__(self,low,high):
> 		return self._data[low:high]

Do this:

> 	def __getslice__(self,low,high):
> 		return this(self._data[low:high])

The problem is that what you're returning from __getslice__ isn't an instance
of your clas.


More information about the Python-list mailing list