环境:PyCharm+Anaconda

python版本:3.6

协程测试:

 #!/usr/bin/env python
# -*- coding:utf-8 -*-
import time def consumer():
r = ''
while True:
n = yield r
if not n:
return
print('[CONSUMER] Consumeing %s...' % n)
time.sleep(1)
r = '200 OK' def produce(c):
c.next()
n = 0
while n < 5:
n = n + 1
print('[PRODUCER] Producing %s...' % n)
r = c.send(n)
print('[PRODUCER] Consumer return: %s' % r)
c.close() if __name__ == '__main__':
c = consumer()
produce(c)

编译报错:

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

python3.6:AttributeError: 'generator' object has no attribute 'next'的更多相关文章

  1. Python错误:AttributeError: 'generator' object has no attribute 'next'解决办法

    今天在学习生成器对象(generation object)运行以下代码时,遇到了一个错误: #定义生成器函数def liebiao(): for x in range(10): yield x#函数调 ...

  2. mygenerator().next() AttributeError: 'generator' object has no attribute 'next'

    def mygenerator(): print ("start ...") yield 5 mygenerator() print ("mygenerator():&q ...

  3. Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'

    使用python的suds包调用webservice服务接口,报错:AttributeError: 'Document' object has no attribute 'set' 调用服务接口代码: ...

  4. 【Python】【亲测好用】安装第三方包报错:AttributeError:'module' object has no attribute 'main'

    安装/卸载第三包可能出现如下问题及相应解决办法: 在pycharm编辑中,使用anconda2更新.卸载第三方包时,出现如下错误: AttributeError:'module' object has ...

  5. Python PyInstaller 打包报错:AttributeError: 'str' object has no attribute 'items'

    pyinstaller打包时报错:AttributeError: 'str' object has no attribute 'items' 网上查询,可能是setuptools比较老: 更新一下 p ...

  6. 解决:pipenv shell报错:AttributeError: 'module' object has no attribute 'run'

    利用pipenv shell切换到虚拟环境时,显示报错:AttributeError: 'module' object has no attribute 'run' 可以看到是d:\program\p ...

  7. pytorch版本问题:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'

    用pytorch加载训练好的模型的时候遇到了如下的问题: AttributeError: 'module' object has no attribute '_rebuild_tensor_v2' 到 ...

  8. Debug 路漫漫-10:AttributeError: 'Embedding' object has no attribute 'get_shape'

    CNN的Embedding层报错: 报错:AttributeError: 'Embedding' object has no attribute 'get_shape' 查了下是这个问题: https ...

  9. PyQt程序执行时报错:AttributeError: 'winTest' object has no attribute 'setCentralWidget'的解决方法

    用QtDesigner设计了一个UI界面,保存在文件Ui_wintest.ui中,界面中使用了MainWindow窗口,窗口名字也叫MainWindow,用PyUIC将其转换成了 Ui_wintest ...

随机推荐

  1. elasticsearch 基础 —— Field Collapsing字段折叠

    允许根据字段值折叠搜索结果.通过按折叠键选择顶部排序文档来完成折叠.例如,下面的查询检索每个用户的最佳推文,并按喜欢的数量对它们进行排序. GET /twitter/_search { "q ...

  2. php中__call与__callstatic()使用

    php 5.3 后新增了 __call 与__callStatic 魔法方法. __call 当要调用的方法不存在或权限不足时,会自动调用__call 方法. __callStatic 当调用的静态方 ...

  3. centos7 利用mailx发送邮件

    当需要服务器定时发送邮件到自己邮箱时,一个邮件服务就很重要了,以下主要是mailx的实现,主要是利用 1.安装mailx 1 yum  install  mailx -y 2.使用到的配置文件只有一个 ...

  4. SCM

    scm即软件配置管理. 软件配置管理(SCM)是指通过执行版本控制.变更控制的规程,以及使用合适的配置管理软件,来保证所有配置项的完整性和可跟踪性,配置管理是对工作成果的一种有效保护. SCM(Sof ...

  5. poland 波兰 时区

    http://www.timeofdate.com/country/Poland 2019年 ~ 2020年波兰夏令时开始结束时间 年份 日期 类型 2019 2019-3-31 夏令时开始   20 ...

  6. linux 性能测试之基准测试工具

    https://niyunjiu.iteye.com/blog/316302 system: lmbench unixbench5.1.2 ubench freebench nbench ltp xf ...

  7. Go的学习 append的使用

    1. package main; import "fmt" func test () { ],,,,}; s:=a[:] fmt.Printf(]) s=append(s,); s ...

  8. html/css 图片展示效果

    demo.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  9. spark的知识的链接

    IDEA 创建scala spark的Mvn项目:https://blog.csdn.net/u014646662/article/details/84618032 Spark详解03Job 物理执行 ...

  10. 浅析 http 接口

     一.HTTP接口 Http协议是建立在TCP协议基础之上的,当浏览器需要从服务器获取网页数据的时候,会发出一次Http请求.Http会通过TCP建立起一个到服务器的连接通道,当本次请求需要的数据完毕 ...