Python URL download

前端 未结 2 636
夕颜
夕颜 2021-01-25 19:35

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&         


        
相关标签:
2条回答
  • 2021-01-25 20:32

    Your method doesn't explicitly return anything, so it returns None

    0 讨论(0)
  • 2021-01-25 20:35

    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
    

    In the absence of an explicit return statement Python returns None which is what you are seeing.

    0 讨论(0)
提交回复
热议问题