【发布时间】:2013-03-26 09:56:57
【问题描述】:
我的 Python 程序中有这个函数:
@tornado.gen.engine
def check_status_changes(netid, sensid):
como_url = "".join(['http://131.114.52:44444/ztc?netid=', str(netid), '&sensid=', str(sensid), '&start=-5s&end=-1s'])
http_client = AsyncHTTPClient()
response = yield tornado.gen.Task(http_client.fetch, como_url)
if response.error:
self.error("Error while retrieving the status")
self.finish()
return error
for line in response.body.split("\n"):
if line != "":
#net = int(line.split(" ")[1])
#sens = int(line.split(" ")[2])
#stype = int(line.split(" ")[3])
value = int(line.split(" ")[4])
print value
return value
我知道
for line in response.body.split
是一个生成器。但我会将 value 变量返回给调用该函数的处理程序。这可能吗?我该怎么办?
【问题讨论】:
-
已经试过了..但我得到了同样的错误......我认为不可能将回报放入生成器......
-
for循环不是生成器;整个函数是因为你有一个yield语句。 -
感谢您的解释!
标签: python return generator tornado