https://blog.csdn.net/hanhanwanghaha宝藏女孩 欢迎您的关注!
欢迎关注微信公众号:宝藏女孩的成长日记
如有转载,请注明出处(如不注明,盗者必究)

TypeError: can’t send non-None value to a just-started generator
翻译过来是:
TypeError:无法将非None值发送到刚启动的生成器
原因如下:
在一个生成器函数未启动之前,是不能传递数值进去。必须先传递一个None进去或者调用一次next(g)方法,才能进行传值操作。
例如:
代码:

def generator_two():while True:x = yieldprint("value:", x)
#g为上面的生成器
g = generator_two()
#程序运行到yield就暂停,等待下一个next#给yield传送值1,yield再将1传给x,继续下一次循环,停在yeild处
g.send(1)
#给yeild传送值2,yield再将2传给x,继续下一次循环,停在yeild处
g.send(2)
#没有给yield传值,打印输出None,继续停在yield处,等待下一个next
next(g)print(next(g))

报错情况:

当我们加上next(g)的时候,自然也就运行出来了
代码:

def generator_two():while True:x = yieldprint("value:", x)
#g为上面的生成器
g = generator_two()
#程序运行到yield就暂停,等待下一个next
next(g)
#给yield传送值1,yield再将1传给x,继续下一次循环,停在yeild处
g.send(1)
#给yeild传送值2,yield再将2传给x,继续下一次循环,停在yeild处
g.send(2)
#没有给yield传值,打印输出None,继续停在yield处,等待下一个next
next(g)print(next(g))

运行结果:

https://blog.csdn.net/hanhanwanghaha宝藏女孩 欢迎您的关注!
欢迎关注微信公众号:宝藏女孩的成长日记
如有转载,请注明出处(如不注明,盗者必究)

TypeError: can‘t send non-None value to a just-started generator-python报错问题相关推荐

  1. Python报错TypeError: 'str' object is not callable

    原文:http://blog.sina.com.cn/s/blog_71f3890901017rsh.html Python报错TypeError: 'str' object is not calla ...

  2. python报错:TypeError: cant multiply sequence by non-int of type float(bug)(csdn标题没法用英文引号,以后注意别搜引号)

    python报错:TypeError: can't multiply sequence by non-int of type 'float' 注意:csdn标题没法用英文引号,以后注意别搜引号!!!! ...

  3. python报错 TypeError: an integer is required

    问题描述: 在本地使用socket向NetAssist传送数据的时候,执行python文件后发现报出python 报错TypeError: an integer is required错误 代码: 1 ...

  4. Python报错TypeError: ‘User‘ object is not iterable

    Python报错TypeError: 'User' object is not iterable 原因 User对象是不可迭代的,我这里是因为User并不是list,所以是不可迭代的,所以不使用迭代即 ...

  5. Python报错 TypeError: Descriptors cannot not be created directly

    Python报错TypeError: Descriptors cannot not be created directly 具体错误: TypeError: Descriptors cannot no ...

  6. Python报错TypeError: Descriptors cannot not be created directly

    Python报错TypeError: Descriptors cannot not be created directly 具体错误: TypeError: Descriptors cannot no ...

  7. python报错TypeError: must be str, not int

    python报错TypeError: must be str, not int 字符串拼接一个整型变量报错,代码如下 for i in range(1,586):res = 'test' + i 报错 ...

  8. python报错:TypeError: missing 1 required positional argument: ‘self‘

    python报错:TypeError:   missing 1 required positional argument: 'self' 问题: class test:def test01(self) ...

  9. Python报错TypeError: Tuple or struct_time argument required

    错误原因,类型出错误啦,转换不了! 我的解决: >>> time.mktime(time.localtime()) 1545053905.0 具体就看下面的! 我的报错: >& ...

  10. python 报错 TypeError: ‘int‘ object is not subscriptable 解决方法

    报错原因 整数上加了下标 不是数组 当作数组 使用 错误情况1: a = 4 c=a[2]# 或者 a = 4 index=2 c=a[index] 报错:line 2, in <module& ...

最新文章

  1. Django1.11模型使用
  2. CodeForces 671C - Ultimate Weirdness of an Array
  3. mysqli_connect_error 乱码解决
  4. Hadoop入门(一)概念与单机安装
  5. php编译称opcode文件,PHP源码保护和性能加速
  6. (算法)最长回文子串
  7. cisco4503端口镜像配置
  8. java多线程与并发之java并发编程实践
  9. Android手势密码解锁设计
  10. HTML 参考手册- (HTML5 标准)
  11. Excel表Ctrl+v和Ctrl shift+v有什么区别_朴素的办公神器——excel
  12. c语言内存不能为written,该内存不能为written的解决方法 has written 和wrote的区别
  13. CKEditor富文本编辑器使用
  14. vue-cli脚手架中使用talkingData埋点的方法
  15. Python五角星画法
  16. GoLang语言:邮件群发器
  17. Python——QQ/微信 邮件 群发技术实现
  18. Android实现横竖屏切换,以及手机横竖屏旋转的时候,实现横竖屏切换
  19. 微信小程序使用后台播放器播放音乐
  20. HDU3446 daizhenyang‘s chess【带花树】

热门文章

  1. c# 计算机ip,C# 获取电脑的IP,网关,MAC,计算机名。。
  2. 二级c语言基础题库100题,二级C语言上题库100题.doc
  3. netty冲突 play sbt_《Netty官方文档》本地传输接口
  4. python编程制作_一种Python编程创作平台的制作方法
  5. mcp证书有什么用_建造师的行情怎么样呢?建造师证书有什么用?
  6. libmysqld_dev linux,Linux下python玩转MySQLdb
  7. 存储器和寄存器数据传输(ARMv8)
  8. linux 开启关闭tomcat服务器端口,linux系统安装、启动和关闭tomcat
  9. VOC2007xml转YOLO的txt格式代码
  10. 基于JavaWeb SSM mybatis 学生信息管理系统设计和实现以及文档报告