I’m a somewhat new to python and was looking through the Django source code. I came across utils.py, and was somewhat confused about what this iterator method does:
def __iter__(self):
return iter(self.file)
What would this be used for?
Iterating through a file yields all its lines, e.g.:
Results in:
if
foo.txtis:(extra newlines because
lineincludes the newlines of the file).So, iterating through an instance of the class whose source you posted a snippet from results in iterating through that instance’s
file‘s lines.