The “idata” I pulled from this URL needs to be turned into a sequence, how do i turn it into a sequence
import urllib, csv
URL = "http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=sl1vt1&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()
return data # <======== Return
idata = fetch_quote(symbols)
print idata
What do you mean by “a sequence”? You could turn it into a dictionary as follows. Just place this code after you produce
idata.If you want to be a bit more robust, you can use the
csvmodule (addimport csvto the top of your code) then useFor inserting into a database, the following may work
This of course assumes your columns are in the same order as the elements of the array.