帮忙看下这段generator代码
def psychologist():
print('Please tell me your problems')
while True:
answer = yield
if answer is not None:
if answer.endswith('?'):
print('Don\'t ask yourself too much questions...')
elif 'good' in answer:
print('That\'t good. Go on.')
elif 'bad' in answer:
print('Be positive. Believe in yourself.')
else:
print('Fuck you. What are you talking about!')
谁能解释下下面的输出?
>>> free = psychologist()
>>> next(free)
Please tell me your problems
>>> free.send('how are you?')
Don't ask yourself too much questions
>>> next(free)
>>> next(free)
>>> next(free)
>>> next(free)
为什么只有第一次在next(free)后面出现那行:Please tell me your problems
而后面不管怎么next(free),都没有任何作用(是真的没有任何作用么?)
求解。
...全文
相关推荐
详解在IDEA中使用MyBatis Generator逆向工程生成代码
主要介绍了详解在IDEA中使用MyBatis Generator逆向工程生成代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
使用mybatis-plus-generator进行代码自动生成的方法
主要介绍了使用mybatis-plus-generator进行代码自动生成的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
faux-code-generator:将真实代码转换为伪代码
faux-code-generator:将真实代码转换为伪代码
vivado的fifo_generator代码
附件是vivado 2018的 fifo source code 对vivado ip 源代码有兴趣,可联系邮箱fpgahelloworld@126.com
js代码-Generator实现斐波那契数列
js代码-Generator实现斐波那契数列


