Python iterators and iterables need not be the same!
Adrian Hintermaier
203

Iterators are defined in the Python documentation as objects implementing both __iter__() and __next__(), so objects of the Iterator class in your example are not, properly speaking, iterator objects. You should add

def __iter__(self): return self

to the Iterator class definition: surprising and unexpected bugs can come out of using Iterator objects as iterator objects (haha) while failing to fully implement the iterator protocol — as you demonstrated with the for e in myiterator example.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.