蟒蛇网址下载 [英] Python URL download
本文介绍了蟒蛇网址下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码返回none
.我该如何解决?我使用的是 Python 2.6.
The code below returns none
. How can I fix it? I'm using Python 2.6.
import urllib
URL = "http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=sl1t1v&e=.csv"
symbols = ('GGP', 'JPM', 'AIG', 'AMZN','GGP', 'JPM', 'AIG', 'AMZN')
#symbols = ('GGP')
def fetch_quote(symbols):
url = URL % '+'.join(symbols)
fp = urllib.urlopen(url)
try:
data = fp.read()
finally:
fp.close()
def main():
data_fp = fetch_quote(symbols)
# print data_fp
if __name__ =='__main__':
main()
推荐答案
你必须从 fetch_quote
函数中显式地return
data
.像这样:
You have to explicitly return
the data
from fetch_quote
function. Something like this:
def fetch_quote(symbols):
url = URL % '+'.join(symbols)
fp = urllib.urlopen(url)
try:
data = fp.read()
finally:
fp.close()
return data # <======== Return
在没有显式返回语句的情况下,Python 返回 None
,这就是您所看到的.
In the absence of an explicit return statement Python returns None
which is what you are seeing.
这篇关于蟒蛇网址下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文