[Python-ideas] Generators are iterators

Alexander Belopolsky alexander.belopolsky at gmail.com
Fri Dec 12 20:41:15 CET 2014

On Fri, Dec 12, 2014 at 12:16 PM, Chris Barker <chris.barker at noaa.gov>

> 2) there are a number of TIPPS in the standard library: things like
> tupleiterator and friends, the range object, etc.

The range object is not an iterator

>>> isinstance(range(1), collections.Iterator)

and does not implement the iterator protocol

>>> range(1).__next__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'range' object has no attribute '__next__'

Please don't confuse iterators and iterables:

>>> isinstance(range(1), collections.Iterable)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141212/645f8099/attachment.html>

More information about the Python-ideas mailing list