mygenerator().next() AttributeError: 'generator' object has no attribute 'next'
def mygenerator():
print ("start ...")
yield 5 mygenerator()
print ("mygenerator():",mygenerator())
mygenerator().next()
我定义了带有yield的函数,调用是报错:
mygenerator().next()
AttributeError: 'generator' object has no attribute 'next'
原因是在python 3.x中 generator(有yield关键字的函数则会被识别为generator函数)中的next变为__next__了,next是python 3.x以前版本中的方法
解决方法:把next()换为:_ _next_ _()
# -*- coding:utf-8 -*-
def mygenerator():
print ("start ...")
yield 5 print ("mygenerator():",mygenerator())
mygenerator().__next__()
mygenerator(): <generator object mygenerator at 0x0000000002324728>
start
mygenerator().next() AttributeError: 'generator' object has no attribute 'next'的更多相关文章
- Python错误:AttributeError: 'generator' object has no attribute 'next'解决办法
今天在学习生成器对象(generation object)运行以下代码时,遇到了一个错误: #定义生成器函数def liebiao(): for x in range(10): yield x#函数调 ...
- [错误处理]AttributeError: 'generator' object has no attribute 'next'
在python3下学习yield用法. 程序如下: def bar(n): m = n while True: m += 1 yield m b = bar(3) print(b.next()) 程序 ...
- python3.6:AttributeError: 'generator' object has no attribute 'next'
环境:PyCharm+Anaconda python版本:3.6 协程测试: #!/usr/bin/env python # -*- coding:utf-8 -*- import time def ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- AttributeError: 'list' object has no attribute 'write_pdf'
我在可视化决策树,运行以下代码时报错:AttributeError: 'list' object has no attribute 'write_pdf' 我使用的是python3.4 from sk ...
- attributeError:'module' object has no attribute ** 解决办法
写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ...
- AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'
/*************************************************************************** * AttributeError: 'modu ...
- AttributeError: 'dict_values' object has no attribute 'translate'
/***************************************************************************************** * Attribu ...
- python3 AttributeError: 'NoneType' object has no attribute 'split'
from wsgiref.simple_server import make_server def RunServer(environ, start_response): start_response ...
随机推荐
- css的基础知识1
总结:css引用:1内联:在标签中加style属性,<标签名 style="样式1:样式值1:样式2:样式值2"> </标签名>.2.内嵌:在head标签中 ...
- [工具]iostat
本文主要分析了Linux的iostat命令的源码 iostat源码共563行,应该算是Linux系统命令代码比较少的了.源代码中主要涉及到如下几个Linux的内核文件: 1./proc/disksta ...
- python爬虫16 | 你,快去试试用多进程的方式重新去爬取豆瓣上的电影
我们在之前的文章谈到了高效爬虫 在 python 中 多线程下的 GIL 锁会让多线程显得有点鸡肋 特别是在 CPU 密集型的代码下 多线程被 GIL 锁搞得效率不高 特别是对于多核的 CPU 来说 ...
- c# SQL事务
SQL事务执行 SqlTransaction sqlTransaction = sqlConnection.BeginTransaction(); SqlCommand sqlC ...
- ubuntu添加开机自启和sysv-rc-conf
此文ubuntu使用sysvinit,而非upstart UBUNTU添加开机自动启动程序方法 1. 开机启动时自动运行程序 Linux加载后, 它将初始化硬件和设备驱动, 然后运行第一个进程i ...
- py文件控制台执行时,报错:引入的模块不存在
1.描述:该模块在IDE中是可以正确执行的.但是从cmd控制台执行时,报错:该模块引入的其他模块不存在. 2.解决:在该模块的#encoding:utf-8 之后另起一行加如下代码: #encodin ...
- Source Insight 与 Source Navigator ,Understand ,Crystal FLOW 源代码阅读工具
http://www.sourceinsight.com/update.html http://www.oschina.net/p/sourcenavigator/ http://www.cnblog ...
- 2014 北京 DevFest 大会能够报名啦,小伙伴们还在等什么
一年一度的大型开发人员活动,2014 北京 DevFest 大会站点正式上线: http://devfest.gdgbeijing.org/. 还等什么,開始报名了! 今年 DevFest 大会将再次 ...
- [Angular] Why should we using Protal
Origianl article Protal from Angular CDK, is a way to create dynammic component. Consider an example ...
- GTK经常使用控件之行编辑( GtkEntry )
行编辑,仅仅同意输入一行内容的控件.如password输入框. 行编辑的创建: GtkWidget *gtk_entry_new(void); 返回值:行编辑指针 设置行编辑内容的最大长度: void ...