Help me with a tricky (for me) Python problem
August 23, 2009 1:00 AM
Subscribe
I am trying to make a python script that takes a CSV file and turns it into an HTML table. I need it to combine a column containing a website name and another column containing a URL into an HTML link.
I'm working on a python script that takes a CSV file and turns it into an HTML table.
The CSV has, among numerous other columns, a column containing a website name and another column containing a URL. I would like to combine the two into an HTML link.
Here is what I have so far that converts the rows & columns into tables:
for row in reader:
html.write('<tr>');
for column in row:
html.write('<td>' + column + '</td>');
html.write('</tr>')
I know the part that makes the HTML link would need to say:
html.write('<a href="'+ URLcolumn + '">' + sitecolumn + '</a></td>')
But I am stumped on how to finish implementing this. In particular, I can't figure out how to "refer" to the URLcolumn and sitecolumn.
posted by Mjolnir to computers & internet (7 comments total)
1 user marked this as a favorite
for row in reader:
html.write('<tr>')
html.write('<a href="'+ row[0] + '">' + row[1] + '</a></td>'")
Or assign them to names:
for row in reader:
html.write('<tr>')
urlcolumn, sitecolumn = row
html.write('<a href="'+ urlcolumn + '">' + sitecolumn + '</a></td>'")
posted by joshu at 1:09 AM on August 23