What makes an iterator an iterator?
Isaac Rodriguez
isaac.rodriguez at comcast.net
Wed Apr 18 09:36:37 EDT 2007
Sorry, my previous post was incomplete. I didn't realized that you
implemented _next() as a generator funcition. Besides changing
__init__() from
self.next = self._next()
to
self.next = self._next
you need to implement __iter__() as:
return self.next()
> class Parrot(object):
> def __iter__(self):
> return self
> def __init__(self):
> self.next = self._next()
> def _next(self):
> for word in "Norwegian Blue's have beautiful plumage!".split():
> yield word
>
More information about the Python-list
mailing list