国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Tornado協(xié)程在python2.7如何返回值(實(shí)現(xiàn)方法)

2020-01-04 16:53:19
字體:
供稿:網(wǎng)友

錯(cuò)誤寫法

class RemoteHandler(web.RequestHandler):   @gen.coroutine  def get(self):    response = httpclient('http://www.baidu.com')    self.write(response.body)   @gen.coroutine  def httpClient(url):    result = yield httpclient.AsyncHTTPClient().fetch(url)    return result

 

按照一般的方法return會(huì)報(bào)錯(cuò)

需要使用 raise gen.Return(response.body) 代替return

官方例子

@gen.coroutinedef fetch_json(url):  response = yield AsyncHTTPClient().fetch(url)  raise gen.Return(json_decode(response.body))

In Python 3.3, this exception is no longer necessary: the return statement can be used directly to return a value (previously yield and return with a value could not be combined in the same function).

在python 3.3以上版本, 不在需要拋出異常,可以直接使用return直接返回值。而在之前的版本中,yield和帶有返回值的return不能處于一個(gè)函數(shù)當(dāng)中。

以上這篇Tornado協(xié)程在python2.7如何返回值(實(shí)現(xiàn)方法)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持VEVB武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 沂源县| 高青县| 安徽省| 邛崃市| 根河市| 鹿邑县| 新龙县| 舒城县| 合阳县| 邯郸县| 新乐市| 大姚县| 城固县| 铜山县| 兴城市| 阿克| 曲阜市| 上蔡县| 平凉市| 延津县| 遵义市| 澜沧| 新沂市| 禹城市| 曲沃县| 沈阳市| 原平市| 沁源县| 张北县| 绥中县| 玛沁县| 昭平县| 伊川县| 运城市| 安平县| 嵊泗县| 茌平县| 陆丰市| 巴中市| 周口市| 启东市|