This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Itertools objects are missing "send"
Type: Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: rhettinger, tebeka
Priority: normal Keywords:

Created on 2009-05-21 20:34 by tebeka, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg88166 - (view) Author: Miki Tebeka (tebeka) * Date: 2009-05-21 20:34
Some (most?) of the itertools functions "generators" do not supprt "send".

>>> from itertools import count
>>> n = count(0)
>>> n.next()
0
>>> n.send(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'itertools.count' object has no attribute 'send'
>>> 

However:
>>> def count(start):
...     while 1:
...         yield start
...         start += 1
... 
>>> n = count(0)
>>> n.next()
0
>>> n.send(1)
1
>>> 

For some of the functions (such as count and repeat), "send" also make
sense.
msg88167 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-05-21 20:39
Why would they?  There is no use case (the data would be thrown away). 
Not every iterator has to support the whole generator protocol.
msg88168 - (view) Author: Miki Tebeka (tebeka) * Date: 2009-05-21 21:24
My bad, thought that every iterator is supposed to implement "send".
I still think that "count" and "repeat" can support and use it.
msg88170 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-05-21 21:30
What do you have in mind for count() or repeat()?  How would they use
the send() value?
History
Date User Action Args
2022-04-11 14:56:49adminsetgithub: 50330
2009-05-21 21:30:27rhettingersetmessages: + msg88170
2009-05-21 21:24:35tebekasetstatus: open -> closed

messages: + msg88168
2009-05-21 20:39:06rhettingersetnosy: + rhettinger
messages: + msg88167
2009-05-21 20:34:18tebekacreate