tags:

views:

63

answers:

2

The Code below gives me "none", How Can I fix? 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()
+1  A: 

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

Zach
How Do I fix, thanks
Uhm, return something?
Santa
+2  A: 

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.

Manoj Govindan
I tested this fix, it works. "GGP",14.65,"12:04pm",689816 ...
msw
thanks, fixed it!!!!