Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

You're getting thrown off by the error message; type-wise, Python doesn't make a distinction - you can .send to anything that uses yield, even if it doesn't 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).


In the case you find yourself patching somebody's code, it seems that the built-in python3 next() function calls the iterator's next() function, so you may be able to find/replace somebody's 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).

Here's 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.