[Tutor] Parsing data from a csv file

louis leichtnam l.leichtnam at gmail.com
Thu Mar 24 13:34:51 CET 2011


Hello,

I am to extract a csv file from the web and parse it in python and after
that make it into an html page.

I want to get the data out of the csv file, get rid of the "," and make it
readable.

Questions:
I would like to be able to print the line I want but I don't know how to do
it.
I would like to modify some lines, and make them cleaner

Can you help me?




import urllib, csv
url=r"http://www.cs.columbia.edu/~joshua/teaching/cs3101/simpsons_diet.csv"
simpsons=urllib.urlopen(url)
reader=csv.reader(simpsons,delimiter=',',quotechar='"')
a=[]
b=[]
c=[]
d=[]
e=[]
for char,meal,ate,qty,com in reader:
    for x in char:
        a.append(x)
    for y in meal:
        b.append(y)
    for z in ate:
        c.append(z)
    for aa in qty:
        d.append(aa)
    for bb in com:
        e.append(bb)
for i in range(1::):
    print a[i]+b[i]+c[i]+d[i]+e[i]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110324/2e556277/attachment.html>


More information about the Tutor mailing list