python3.6:AttributeError: 'generator' object has no attribute 'next'
环境: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'的更多相关文章
- Python错误:AttributeError: 'generator' object has no attribute 'next'解决办法
今天在学习生成器对象(generation object)运行以下代码时,遇到了一个错误: #定义生成器函数def liebiao(): for x in range(10): yield x#函数调 ...
- mygenerator().next() AttributeError: 'generator' object has no attribute 'next'
def mygenerator(): print ("start ...") yield 5 mygenerator() print ("mygenerator():&q ...
- Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'
使用python的suds包调用webservice服务接口,报错:AttributeError: 'Document' object has no attribute 'set' 调用服务接口代码: ...
- 【Python】【亲测好用】安装第三方包报错:AttributeError:'module' object has no attribute 'main'
安装/卸载第三包可能出现如下问题及相应解决办法: 在pycharm编辑中,使用anconda2更新.卸载第三方包时,出现如下错误: AttributeError:'module' object has ...
- Python PyInstaller 打包报错:AttributeError: 'str' object has no attribute 'items'
pyinstaller打包时报错:AttributeError: 'str' object has no attribute 'items' 网上查询,可能是setuptools比较老: 更新一下 p ...
- 解决:pipenv shell报错:AttributeError: 'module' object has no attribute 'run'
利用pipenv shell切换到虚拟环境时,显示报错:AttributeError: 'module' object has no attribute 'run' 可以看到是d:\program\p ...
- pytorch版本问题:AttributeError: 'module' object has no attribute '_rebuild_tensor_v2'
用pytorch加载训练好的模型的时候遇到了如下的问题: AttributeError: 'module' object has no attribute '_rebuild_tensor_v2' 到 ...
- Debug 路漫漫-10:AttributeError: 'Embedding' object has no attribute 'get_shape'
CNN的Embedding层报错: 报错:AttributeError: 'Embedding' object has no attribute 'get_shape' 查了下是这个问题: https ...
- PyQt程序执行时报错:AttributeError: 'winTest' object has no attribute 'setCentralWidget'的解决方法
用QtDesigner设计了一个UI界面,保存在文件Ui_wintest.ui中,界面中使用了MainWindow窗口,窗口名字也叫MainWindow,用PyUIC将其转换成了 Ui_wintest ...
随机推荐
- 解决WordPress设置错误的url网站不能访问
由于设置了未备案的域名,而导致网站访问不了了.同时WordPress是使用docker搭建部署的 docker ps #查看 docker 容器 CONTAINER ID IMAGE COMMAND ...
- Dubbo源码学习总结系列二 dubbo-rpc远程调用模块
dubbo本质是一个RPC框架,我们首先讨论这个骨干中的骨干,dubbo-rpc模块. 主要讨论一下几部分内容: 一.此模块在dubbo整体框架中的作用: 二.此模块需要完成的需求功能点及接口定义: ...
- 270-VC709E 增强版 基于FMC接口的Xilinx Vertex-7 FPGA V7 XC7VX690T PCIeX8 接口卡
VC709E 增强版 基于FMC接口的Xilinx Vertex-7 FPGA V7 XC7VX690T PCIeX8 接口卡 一.板卡概述 本板卡基于Xilinx公司的FPGA XC7V ...
- Django组件——Cookie与session相关
一,会话跟踪技术 1 什么是会话跟踪技术我们需要先了解一下什么是会话!可以把会话理解为客户端与服务器之间的一次会晤,在一次会晤中可能会包含多次请求和响应.例如你给10086打个电话,你就是客户端,而1 ...
- Go 使用 append 向切片增加元素
1.// 创建一个整型切片 // 其长度和容量都是 5 个元素 slice := []int{10, 20, 30, 40, 50} // 创建一个新切片 // 其长度为 2 个元素,容量为 4 个元 ...
- $Noip$前的小总结哦
考试失误点与积累 有点不知道该干嘛了,状态有点差,写点东西.(后面可能会加更一点东西?) 常规错误 \(1.\) 数组开小 \(2.\) \(int\)和\(longlong\) \(3.\) 开某题 ...
- HTTP协议-get请求与post请求的区别
区别: 参数:get通过url进行传递:post放在request body中 长度:get请求在url的长度是有限制的:而post没有(其实这个限制是来自浏览器和web服务器对url的限制,并不是h ...
- HTTP协议缓存
缓存的概念 缓存这个东西真的是无处不在, 有浏览器端的缓存, 有服务器端的缓存,有代理服务器的缓存, 有ASP.NET页面缓存,对象缓存. 数据库也有缓存, 等等. http中具有缓存功能的是浏览器缓 ...
- centos7在线安装mysql8.0.16
一.官网复制安装源地址: 1.进入官网地址:https://dev.mysql.com/downloads/repo/yum/ 二.进入/usr/local目录下 ,创建mysql文件夹 三.使用命令 ...
- 一次服务器CPU占用100%的问题排查
今天写了一段垃圾代码,然后上服务器上运行,cpu瞬间飙到了100%,现记录一下问题排除过程~ 1. 问题代码 package qinfeng.zheng.mockmvcdemo; import org ...