How do you refer to an iterator in docs?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Apr 20 03:11:58 EDT 2012
I refer you to your subject line:
"How do you refer to an iterator in docs?"
In documentation, I refer to an iterator as an iterator, just as I would
refer to a list as a list, a dict as a dict, or a string as a string.
You may also find these useful:
sequence
something that obeys the sequence protocol, e.g. a list or a tuple
iterator
something which obeys the iterator protocol
iterable
something that can be iterated over, such as an iterator or a sequence
The sequence protocol is that the object should be indexed by consecutive
integers 0, 1, 2, ... and will raise IndexError when the index is past
the end of the sequence.
The iterator protocol is a little more complicated. To be a true iterator:
1) iter(obj) should return obj;
2) it should have a __next__ method (formerly: next without the
underscores) which takes no arguments and returns a value;
3) the __next__ method should raise StopIteration once the iterator is
exhausted.
--
Steven
More information about the Python-list
mailing list