list element of a class with the for statement
Luigi Ballabio
ballabio at mac.com
Tue Mar 26 10:30:37 EST 2002
At 02:41 PM 3/26/02 +0100, Tjabo Kloppenburg wrote:
>or, in python 2.2 syntax:
>
> def __iter__(self):
> self.ptr = 0
> return self
>
> def next(self):
> if self.ptr < (len(self.__records) - 1):
> self.ptr = self.ptr + 1
> return self.__records[self.ptr]
> else:
> raise StopIteration
def __iter__(self):
return iter(self.__records)
should do the job without having to go through all that machinery...
Bye,
Luigi
More information about the Python-list
mailing list