'generator' object has no attribute 'next'
时间: 2023-04-10 16:04:46 浏览: 124
这个错误是因为在 Python 3 中,'next' 方法已经被替换为 '__next__' 方法,所以在使用生成器时,应该使用 '__next__' 方法而不是 'next' 方法。你可以将代码中的 'next' 方法替换为 '__next__' 方法来解决这个问题。
相关问题
generator object has no attribute next
在Python3中,generator对象不再具有next()方法,而是使用__next__()方法来获取下一个值。因此,如果你在Python3中使用generator对象的next()方法,会导致'generator object has no attribute 'next''的错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
AttributeError: 'generator' object has no attribute 'next'
This error occurs when you are trying to access the next element of a generator object using the `.next()` method which does not exist in Python 3.x. Instead, you should use the built-in `next()` function.
For example, if you have a generator object `gen` and you want to access the next element, you should use:
```
next(gen)
```
This will return the next element of the generator object.
阅读全文