Skip to content Skip to sidebar Skip to footer

Creating A Html Table With Python

I'm stuck on creating a HTML Table for this code here. have to try to output all the dir() of list, dict, tuple, str, int, and float in a HTML table with a limit of 7 column per ro

Solution 1:

Try this

#!/usr/local/bin/python3

print('Content-type: text/html\n')

table = []
table.append("<table>\n")
for obj in [list, dict, tuple, str, int, float]:
    table.append("\t<tr>\n")
    td = []
    for key in dir(obj)[:7]:
        td.append("<td>{0}</td>".format(key))
    table.append("\t\t"+"".join(td))
    table.append("\n\t</tr>\n")

table.append("</table>")

print("".join(table))

Post a Comment for "Creating A Html Table With Python"