"Bulba!" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Thanks to everyone for their responses, but it still doesn't work re > returning next() method: >>>> > class R3: > def __init__(self, d): > self.d=d > self.i=len(d) > def __iter__(self): > d,i = self.d, self.i > while i>0: > i-=1 > yield d[i] > >>>> p=R3('eggs') >>>> p.next()
This is the wrong test for what I and some others thought you were asking. The requirement for p to be an *iterable* and useable in code such as 'for i in p' is that iter(p), not p itself, have a .next method, and iter(p) will. Try ip=iter(p) followed by ip.next and ip.next() instead. If, for whatever reason, you instead want p to actually be an *iterator* with a .next (or .getitem) method, then, of course, you have to actually give it a .next (or .getitem) method. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list