[Tutor] Iterable Understanding

Stephen Nelson-Smith sanelson at gmail.com
Mon Nov 23 09:57:16 CET 2009


Martin,

>    def __iter__(self):
>        while True:
>            for logline in self.logfile:
>                heappush(self.heap, (timestamp(logline), logline))
>                if len(self.heap) >= self.jitter:
>                    break
>            try:
>                yield heappop(self.heap)
>            except IndexError:
>                raise StopIteration

In this __iter__ method, why are we wrapping a for loop in a while True?

S.


More information about the Tutor mailing list