|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! ![]() |
|
#2
|
|||
|
|||
|
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> |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
Thanks for the reply guys! I will try them out as soon as I can.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Printing Table Data |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|