class a(object):
w={'a':'aaa','b':'bbb'}
def __iter__(self):
return iter(self.w)
def next(self):#this is not be called
print 'sss'
for i in self.w:
return i
b=a()
for i in b:
print i
and what is Relations between __iter__ and next function.
thanks
I’m not entirely sure what you are asking, but the
next()function isn’t called because you never explicitly call it. You define__iter__, which gets called when you do:This should implicitly call the .next() method of the iterator, but the iterator isn’t
a, but ratheriter(self.w). As your object is not the iterator, itsnext()method is never called.Hope this helps.