July 12th, 2004, 02:44 PM
-
Printing Table Data
Hello,
I always find myself printing data in tables. Does anyone know of a cool script that I can use that would automatically print out the data in a table in a formatted way, html-zied or not? Thanks!
July 14th, 2004, 04:40 AM
-
table = get_table()
print '<html><body><table>'
for r in table:
print '<tr>'
for c in r:
print '<td>'
print c
print '</td>'
print '</tr>'
print '</table></body></html>
July 14th, 2004, 05:59 AM
-
Please use code tags in future, also, read the sticky regarding how to post!
Code:
table = ((1, 2, 3), (4, 5, 6))
print '<table>'
for row in table:
print ' <tr>'
for col in row: print ' <td>%s</td>' % col
print ' </tr>'
print '</table>'
This will work fine - the spaces here are simply to indent the HTML for easy reading, if that doesnt matter to you just remove any white space at the beginning of the print statments.
Remember, you'll have to make sure that each row contains the same number of columns or you're table will break!
Mark.
July 22nd, 2004, 06:46 PM
-
Thanks for the reply guys! I will try them out as soon as I can.