I am a little bit lost on python iterators. I occasionally use them, but I don’t remember creating one myself. I read from somewhere that I don’t remember where, a code like this:
class Foo(object):
def __init__(self):
self.something = "initial_value"
def __iter__(self):
return self
def next(self):
# I don't quite remember what was here :S
return self.something
I guess __iter__() method supposed to return an iterator, and that iterator should have a next method right? Then what about __next__() method? is it for directly iterating over a class without it returning another iterator with __iter__() method?
PEP 3114 renamed
iterator.next()toiterator.__next__(). This was implemented in version 3.0. The link above contains all the gory details.