I have the following code in django.template:
class Template(object):
def __init__(self, template_string, origin=None, name=\'\'):
That __iter__
method returns a python generator (see the documentation), as it uses the yield
keyword.
The generator will provide the next() method automatically; quoting the documentation:
What makes generators so compact is that the __iter__() and next() methods are created automatically.
EDIT:
Generators are really useful. If you are not familiar with them, I suggest you readup on them, and play around with some test code.
Here is some more info on iterators and generators from StackOverflow.