16
私はPythonプログラムでこの機能を持っている:のPythonでSyntaxError:( "発電機内部の引数で '復帰'"、)
@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変数を返します。これは可能ですか?どのようにできるのか?
「yield value」。 – katrielalex
すでに試してみましたが、同じエラーが発生しました...ジェネレータにリターンを入れることは不可能だと思います... – sharkbait
'for'ループはジェネレータではありません。あなたが 'yield'ステートメントを持っているので、関数全体があります。 – geoffspear