gpt4 book ai didi

python-2.7 - python simpy错误返回生成器内部的值

转载 作者:行者123 更新时间:2023-12-03 08:27:30 30 4
gpt4 key购买 nike

运行以下代码时出现错误

File "simpy.py", line 4
return 'Monty Pythons Flying Circus'
SyntaxError: 'return' with argument inside generator

这是一个 code sample from simpy official site

我尝试了 this solution given to a similar looking question,但随后出现以下错误:
Invalid yield value "Monty Pythons Flying Circus"

来自simpy网站的代码:
import simpy
def my_proc(env):
yield env.timeout(1)
return 'Monty Pythons Flying Circus'

env = simpy.Environment()
proc = env.process(my_proc(env))
env.run(until=proc)

我按照上面引用的解决方案尝试过的修改后的代码如下:
import simpy
def my_proc(env):
yield env.timeout(1)
yield 'Monty Pythons Flying Circus'
return
env = simpy.Environment()
proc = env.process(my_proc(env))
env.run(until=proc)

此代码给出了错误 Invalid yield value "Monty Pythons Flying Circus"
如何解决这个问题?

最佳答案

我遇到了同样的错误,并将其跟踪到代码here
读取Process类的代码和文档字符串:

A generator (also known as a coroutine) can suspend its execution by yielding an event. Process will take care of resuming the generator with the value of that event once it has happened.



我了解问题是 您没有产生事件,而是一个字符串

关于python-2.7 - python simpy错误返回生成器内部的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45265981/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com