How to make slicing and other methods interact?

Tim Churches tchur at optushome.com.au
Mon Jun 2 08:15:41 EDT 2003


From: python-list-admin at python.org [mailto:python-list-admin at python.org]
> On Behalf Of Michael Davidson
> Sent: Tuesday, 3 June 2003 7:50 AM
> To: Tim Churches
> Cc: Pythonistas; staff at object-craft.com.au
> Subject: Re: How to make slicing and other methods interact?
> 
> On Mon, 02  2003, Tim Churches (tchur at optushome.com.au) 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.

Duh! That's the insight I needed. Many thanks.

Tim C 








More information about the Python-list mailing list