I get a little lost on python iterators. Sometimes I use them, but I don’t remember being created. I read 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):
return self.something
I assume that the method __iter__()should return an iterator, and that the iterator should have the following method correctly? Then what about the method __next__()? is it for direct iteration over a class if it does not return another iterator using the method __iter__()?
yasar source
share