Iterator - what I am missing
jarausch at skynet.be
Thu Aug 14 21:08:32 CEST 2003
I cannot find out what I miss with my iterator example.
I have a linked list class Queue which has a 'Head' attribute
and the following
if self.Head == None: raise StopIteration
The elements of the list are of class Node
which has a 'NNd' (next Node) attribute and
a next method
if N == None: raise StopIteration
Now when I try to iterate over all elements of the
Queue like in (MyQ is an instance of class Queue)
for N in MyQ:
I get an infinite loop and 'N' always refers to the first
element of the MyQ as initialized by MyQ.__iter__
I've checked 'MyQ' and it contains 2 elements and 'NNd'
attribute of the last one is 'None'
So what's going on here?
Many thanks for a hint,
Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
More information about the Python-list