[Tutor] Fw: Fw: Parsing data from a csv file [NC]

Rafael Durán Castañeda rafadurancastaneda at gmail.com
Thu Mar 24 16:37:01 CET 2011


Ok, I think what you are trying is to get all data in a string list:

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='"')

list_string = []

for char,meal,ate,qty,com in reader:
   if char != 'Character':
      list_string.append("%s %s %s %s %s" % (char, meal, ate, qty, com))

print list_string

Doing something like this you can format all strings as you want and keep
them into a list

2011/3/24 <l.leichtnam at gmail.com>

> Thanks, what I'm trying to do is extract the data from the csv file, clean
> it to make each line into a sentence.
>
> But for this I think I need to use a dictionary for each and enter the
> words of each columns in one no?
> Sent from my BlackBerry® on the MetroPCS Network
>
> -----Original Message-----
> From: Rafael Durán Castañeda
>        <rafadurancastaneda at gmail.com>
> Sender: tutor-bounces+l.leichtnam=gmail.com at python.org
> Date: Thu, 24 Mar 2011 15:51:34
> To: <tutor at python.org>
> Subject: Re: [Tutor] Fw: Fw: Parsing data from a csv file [NC]
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110324/4d343e6e/attachment.html>


More information about the Tutor mailing list