python3.x中運行生產器AttributeError: 'generator' object has no attribute 'next'解決

在python3.x中需要將以前版本中的next改爲:__next__
 

def simpleGen():
    yield 1
    yield '2 --> punch!'

myG = simpleGen()
for eachItem in myG:
    print(eachItem)

運行結果:

1
2 --> punch!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章