V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  binux  ›  全部回复第 263 页 / 共 338 页
回复总数  6749
1 ... 259  260  261  262  263  264  265  266  267  268 ... 338  
2014-05-31 17:38:07 +08:00
回复了 chengxuan 创建的主题 Python 求助 python 报错误 给予解决者 100 元话费
def get_huobi_seller(self):
try:
r = requests.get('http://market.huobi.com/staticmarket/depth_btc_json.js')
return r
except:
time.sleep(18)
self.get_huobi_seller()

你看,except 里面没有 return 啊,`return self.get_huobi_seller()`
虽然不建议,如果一直失败会导致爆栈的
2014-05-31 17:11:48 +08:00
回复了 chengxuan 创建的主题 Python 求助 python 报错误 给予解决者 100 元话费
@chengxuan 我继续猜
请求api封装的时候,为了防止异常,是这么写的

try:
__return requests.post('http://some.api.com/')
except:
__pass

当多次访问之后,requests 出现了
ConnectionError: HTTPConnectionPool(host='some.api.com', port=80): Max retries exceeded with url: /
异常,没有办法 return,于是,函数实际返回空

后面处理没有做判断,亦然调用 ret.json(),于是报错
2014-05-31 15:48:47 +08:00
回复了 chengxuan 创建的主题 Python 求助 python 报错误 给予解决者 100 元话费
让我猜猜,你用的是requests?然后又自己封装了一层,应该返回 response object 的
然后,没有 returen 或者 return 为空了,外面的函数接着调用了 ret.json() 于是失败了?
不整理,要用的时候 ack,如果一点片段都记不住,怎么整理都没用。
2014-05-30 21:19:13 +08:00
回复了 sennes 创建的主题 问与答 Python 局域网 投票系统
更正下服务器代码,把 finish 统计进去了

while true; do QUIT=`nc -l 9999`; [[ $QUIT == "finish" ]] && break || echo $QUIT; done | tee vote.log | awk '{ a[$1]++ } END { for(k in a) print k, a[k]; }' | sort -k2nr
2014-05-30 21:13:17 +08:00
回复了 sennes 创建的主题 问与答 Python 局域网 投票系统
./server.sh
#/bin/bash
QUIT=""; while [[ $QUIT != "finish" ]];do QUIT=`nc -l 9999` && echo $QUIT; done | tee vote.log | awk '{ a[$1]++ } END { for(k in a) print k, a[k]; }' | sort -k2nr

./vote.sh
#/bin/bash
echo $1 | nc localhost 9999

./finish.sh
#/bin/bash
echo "finish" | nc localhost 9999
2014-05-30 11:48:20 +08:00
回复了 JoyNeop 创建的主题 问与答 至阴之数 6 乘以至阳之数 9 刚好是 42,是个巧合吗?
3乘8也刚好是42,在5.5进制里
1 ... 259  260  261  262  263  264  265  266  267  268 ... 338  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3839 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 45ms · UTC 00:10 · PVG 08:10 · LAX 17:10 · JFK 20:10
Developed with CodeLauncher
♥ Do have faith in what you're doing.