Skip to content

Commit

Permalink
correct csv and cobbled together python
Browse files Browse the repository at this point in the history
  • Loading branch information
cweber committed Aug 20, 2014
1 parent ab2a4e0 commit 0b48836
Show file tree
Hide file tree
Showing 2 changed files with 417 additions and 23 deletions.
49 changes: 26 additions & 23 deletions cookbook.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
# import csv functionality
import csv


html = "<body>"

# opening in a way that will close the file when we are done
with open("recipes.csv", "rU") as csvfile:
# reading file
reader = csv.reader(csvfile)

rownum = 0
for row in reader:
# Save header row.
if rownum == 0:
header = row
if rownum == 1:
colnum = 0
for col in row:
print '%s: %s' % (header[colnum], col)
colnum += 1
#else:
# colnum = 0
# for col in row:
# print '%s: %s' % (header[colnum], col)
# colnum += 1

rownum += 1


html = html + "div"
#for data in row:
# html = html + "<td>" + data + "</td>"


html = html +"</div>\n"

html = html + "</body>"

print(html)







html = "<table>"
# writing out the header of the html
html = html + "<thead><tr><th>title1</th><th>title2</th><th>title3</th></tr></thead><tbody>\n"

with open("eggs.csv", "rU") as csvfile:
reader = csv.reader(csvfile)
for row in reader:
# we replaced this written out line with a loop below
# html = html + "<td>" + row[0] + "</td><td>" + row[1] + "</td><td>" + row[2] + "</td>
html = html + "<tr>"
for data in row:
html = html + "<td>" + data + "</td>"
html = html +"</tr>\n"

html = html + "</tbody></table>"

html = html + "</body>"
Loading

0 comments on commit 0b48836

Please sign in to comment.