I\'m new to python and having issues with the CSV parser. Here is the code:
import urllib2
import csv
u = urllib2.urlopen(r\'http://finance.yahoo.com/d/quotes.
Just parse u
directly into the reader:
import urllib2
import csv
u = urllib2.urlopen(r'http://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT&f=nab')
reader = csv.reader(u)
for row in reader:
print row
The problem is that csv.reader
accepts an iterable of lines. When you pass it a string, it thinks each character is a line. In fact, the reason it doesn't just give single-character elements is due the the quotation marks.
u
is already an iterable of lines, so it's fine to just pass in.