On 19 Feb 2010, at 17:12 , Andrey Fedorov wrote:
Since .next() seems to be equivalent to .send(None), why wasn't .next() just given an optional parameter which defaults to None?
You'd have to check the ML discussions on PEP 342 (Coroutines via Enhanced Generators). The PEP explicitly states that send(None) is equivalent to next()
A new method for generator-iterators is proposed, called send(). It
takes exactly one argument, which is the value that should be "sent in" to the generator. Calling send(None) is exactly equivalent to calling a generator's next() method. Calling send() with any other value is the same, except that the value produced by the generator's current yield expression will be different.
A new method was probably created because it would be quite unclear that `next(value)` sends that value into the generator for consumption by a yield expression. Whereas the purpose of `send(value)` looks pretty obvious.