__next__ and StopIteration
Charles Hixson
charleshixsn at earthlink.net
Mon Feb 9 14:14:55 EST 2015
I'm trying to write a correct iteration over a doubly indexed container,
and what I've got so far is: def __next__ (self):
for row in range(self._rows):
for col in range(self._cols):
if self._grid[row][col]:
yield self._grid[row][col]
#end if
#end for col
#end for row
raise StopIteration
What bothers me is that it doesn't look like it would continue to raise
StopIteration if it were called again, which is what
https://docs.python.org/3/library/stdtypes.html#iterator.__next__ says
is correct. How should this be fixed?
More information about the Python-list
mailing list