Python-3.2 coroutine: AttributeError: generator object has no attribute next

Python-3.2 coroutine: AttributeError: generator object has no attribute next

Youre getting thrown off by the error message; type-wise, Python doesnt make a distinction – you can .send to anything that uses yield, even if it doesnt do anything with the sent value internally.

In 3.x, there is no longer a .next method attached to these; instead, use the built-in free function next:

next(matcher)

For python version 3.2 the syntax for the next() in-built function should be matcher.__next__() or next(matcher).

Python-3.2 coroutine: AttributeError: generator object has no attribute next

In the case you find yourself patching somebodys code, it seems that the built-in python3 next() function calls the iterators next() function, so you may be able to find/replace somebodys python2 .next( with the python3-tolerable .__next__( as I just did to make portions of the primefac module work in python3 (among other trivial changes).

Heres the reference:

next(iterator[, default])

Retrieve the next item from the iterator by calling its next()
method. If default is given, it is returned if the iterator is
exhausted, otherwise StopIteration is raised.

Leave a Reply

Your email address will not be published. Required fields are marked *