<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> </head>Thank you for your help<p>Sent from my BlackBerry® on the MetroPCS Network</p><hr/><div><b>From: </b> Louis LEICHTNAM <louis.leichtnam@sgcib.com>
</div><div><b>Date: </b>Thu, 24 Mar 2011 09:48:04 -0400</div><div><b>To: </b><l.leichtnam@gmail.com></div><div><b>Subject: </b>Re: Fw: [Tutor] Parsing data from a csv file [NC]</div><div><br/></div>
<br><font size=2 face="sans-serif">Hello the loops are a bit different,
and I definitely don't know if it's correct but I want to be able to put
each part of the cvs into my future html code.</font>
<br>
<br><font size=2 face="sans-serif">the cvs file is this one: </font>
<br>
<br>
<br><font size=2 face="sans-serif">and can be found there </font><a href=http://www.cs.columbia.edu/%7Ejoshua/teaching/cs3101/simpsons_diet.csv target=_blank><font size=3 color=blue><u>http://www.cs.columbia.edu/~joshua/teaching/cs3101/simpsons_diet.csv</u></font></a>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40% rowspan=2><font size=1 face="sans-serif"><b>l.leichtnam@gmail.com</b>
</font>
<p><font size=1 face="sans-serif">03/24/2011 09:42 AM</font>
<table border>
<tr valign=top>
<td bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
l.leichtnam@gmail.com</font></div></table>
<br>
<td width=59%>
<tr valign=top>
<td>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">Louis LEICHTNAM/us/socgen@socgen</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Fw: [Tutor] Parsing data from a csv
file</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=3><br>
</font>
<br><font size=3>On Thu, Mar 24, 2011 at 8:34 AM, louis leichtnam <</font><a href=mailto:l.leichtnam@gmail.com><font size=3 color=blue><u>l.leichtnam@gmail.com</u></font></a><font size=3>>
wrote:</font>
<br><font size=3>Hello,</font>
<br>
<br><font size=3>I am to extract a csv file from the web and parse it in
python and after that make it into an html page.</font>
<br>
<br><font size=3>I want to get the data out of the csv file, get rid of
the "," and make it readable. </font>
<br>
<br><font size=3>Questions:</font>
<br><font size=3>I would like to be able to print the line I want but I
don't know how to do it.</font>
<br><font size=3>I would like to modify some lines, and make them cleaner</font>
<br>
<br><font size=3>Can you help me?</font>
<br>
<br>
<br>
<br>
<br><font size=3>import urllib, csv</font>
<br><font size=3>url=r"</font><a href=http://www.cs.columbia.edu/%7Ejoshua/teaching/cs3101/simpsons_diet.csv target=_blank><font size=3 color=blue><u>http://www.cs.columbia.edu/~joshua/teaching/cs3101/simpsons_diet.csv</u></font></a><font size=3>"</font>
<br><font size=3>simpsons=urllib.urlopen(url)</font>
<br><font size=3>reader=csv.reader(simpsons,delimiter=',',quotechar='"')</font>
<br><font size=3>a=[]</font>
<br><font size=3>b=[]</font>
<br><font size=3>c=[]</font>
<br><font size=3>d=[]</font>
<br><font size=3>e=[]</font>
<br><font size=3>for char,meal,ate,qty,com in reader:</font>
<br><font size=3><br>
at this point you have the five fields you want<br>
if you do print char, meal, ate, qty,com you will see your data with the
commas gone<br>
</font>
<br><font size=3> for x in char:</font>
<br><font size=3> a.append(x)</font>
<br><font size=3> for y in meal:</font>
<br><font size=3> b.append(y)</font>
<br><font size=3> for z in ate:</font>
<br><font size=3> c.append(z)</font>
<br><font size=3> for aa in qty:</font>
<br><font size=3> d.append(aa)</font>
<br><font size=3> for bb in com:</font>
<br><font size=3> e.append(bb)</font>
<br><font size=3>for i in range(1::):</font>
<br><font size=3> print a[i]+b[i]+c[i]+d[i]+e[i]</font>
<br>
<br><font size=3><br>
These for loops puzzle me. It looks like you are iterating over each
character in each variable, then creating a list containing each character.<br>
I don't think you want to do that.<br>
<br>
The for i in range(1::): will give you an error. The range parameter
needs to be something with a length, like a string, or a list, or a tuple.<br>
<br>
Can you show a little bit of your data file, and give us the traceback
and output of your program? </font>
<br><font size=3>_______________________________________________<br>
Tutor maillist - </font><a href=mailto:Tutor@python.org><font size=3 color=blue><u>Tutor@python.org</u></font></a><font size=3><br>
To unsubscribe or change subscription options:</font><font size=3 color=blue><u><br>
</u></font><a href=http://mail.python.org/mailman/listinfo/tutor target=_blank><font size=3 color=blue><u>http://mail.python.org/mailman/listinfo/tutor</u></font></a><font size=3><br>
</font>
<br><font size=3><br>
<br>
<br>
-- <br>
Joel Goldstick<br>
</font>
<br><pre>
*************************************************************************
This message and any attachments (the "message") are confidential, intended
solely for the addressee(s), and may contain legally privileged information.
Any unauthorised use or dissemination is prohibited. E-mails are susceptible
to alteration. Neither SOCIETE GENERALE nor any of its subsidiaries or
affiliates shall be liable for the message if altered, changed or falsified.
*************************************************************************
</pre>
</html>