0

I have a python list which I imported from a CSV and I have sorted the data but know I need to find out how can I convert my list to a html table output. T

import csv

with open('bike_results.csv', 'r') as f:
  reader = csv.reader(f, delimiter=' ',
                        quotechar='|', quoting=csv.QUOTE_MINIMAL)
  bike_list = list(reader)

print(bike_list)
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

-1

Please find the below code for your query by assuming the first line is the header for your HTML table

import csv

with open('results.csv', 'r') as f:
    reader = csv.reader(f, delimiter=' ',
                    quotechar='|', quoting=csv.QUOTE_MINIMAL)
    bike_list = list(reader)
    html_content = "<html><body><table><tr><td>" + bike_list[0][0] + "</td><td>" + bike_list[0][1] + "</td></tr>"
i=1
while i < len(bike_list):
    html_content += "<tr><td>{}</td><td>{}</td></tr>".format(bike_list[i][0],bike_list[i][1])
    i+=1
html_content += "</table></body></html>"

print html_content

Arockia
  • 440
  • 1
  • 6
  • 18