首页 > 其他 > 详细

[错误处理]AttributeError: 'generator' object has no attribute 'next'

时间:2018-06-04 10:11:33      阅读:507      评论:0      收藏:0      [点我收藏+]

在python3下学习yield用法。

程序如下:

def bar(n):
    m = n 
    while True:
        m += 1
        yield m 
b = bar(3)
print(b.next())

程序报错

'generator' object has no attribute 'next'

错误原因

python 3.x中 generator(有yield关键字的函数则会被识别为generator函数)中的next变为__next__了,next是python 3.x以前版本中的方法。

[错误处理]AttributeError: 'generator' object has no attribute 'next'

原文:https://www.cnblogs.com/everfight/p/python_next.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!