PDA

View Full Version : Python: Generator object has no attribut __next__()



koala114
July 21st, 2010, 04:26 PM
I'm trying to figure out generator function, when I print __next__(), python says
AttributeError: 'generator' object has no attribute '__next__'

Has the __next__ method been removed from 2.6.5?

On my ubuntu box is Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)

Compyx
July 21st, 2010, 05:06 PM
The method is called 'next', no leading or trailing underscores.

StephenF
July 22nd, 2010, 02:23 AM
In python 3 you have __next__ and also a 'next' built-in function that calls the __next__ method.



a = (x for x in range(10))
# Python 2
a.next()
# Python 3
next(a)

This change is in keeping with the otherwise general uniformity of the language, or wart -= 1.