From: aa8vb at yahoo.com (Randall Hopper)
Date: Thu, 20 May 1999 10:52:16 -0400
Subject: Sorry, another simple question
In-Reply-To: <7huq5u$hsb@wapping.ecs.soton.ac.uk>; from Joseph Kuan on Wed, May 19, 1999 at 04:51:10PM +0000
References: <7huq5u$hsb@wapping.ecs.soton.ac.uk>
Message-ID: <19990520105216.A421239@vislab.epa.gov>
X-UID: 1731                                                

Joseph Kuan:
 |	How to derive the range function for a particular class?
 |
 |I tried with __range__ but it doesn't work.

Joseph, do you want to do something like this?

    mylist = MyList()

    for element in mylist:
      ...

Or something like this:

    mylist = MyList()

    print mylist[5:10]

If the former, __getitem__ is the method you need.  It's called with
successively increasing index values in the for loop until an IndexError
exception is triggered (IIRC):

    http://www.python.org/doc/current/ref/sequence-types.html

If the latter, look at __getslice__:

    http://www.python.org/doc/current/ref/sequence-methods.html

Randall

   




