keboo hat geschrieben:Johannes
Hi Johannes!
Suchst du so etwas?
Code: Alles auswählen
table = [
['row1','row2','row3'],
[1,2,3],
[1,2,3],
[1,2,3],
[1,2,3],
[1,2,3]
]
#
# Variante 1 (print)
#
print "<table>"
#Kopf
print " <tr>"
for col in table[0]:
print " <th>%s</th>" % col
print " </tr>"
#Daten
for row in table[1:]:
print " <tr>"
for col in row:
print " <td>%s</td>" % col
print " </tr>"
print "</table>"
#
# Variante 2 (Liste)
#
ret = []
ret.append("<table>")
#Kopf
ret.append(" <tr>")
for col in table[0]:
ret.append(" <th>%s</th>" % col)
ret.append(" </tr>")
#Daten
for row in table[1:]:
ret.append(" <tr>")
for col in row:
ret.append(" <td>%s</td>" % col)
ret.append(" </tr>")
ret.append("</table>")
print "\n".join(ret)
Code: Alles auswählen
<table>
<tr>
<th>row1</th>
<th>row2</th>
<th>row3</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>
mfg
Gerold
PS: Mit DocbookXML habe ich nichts am Hut.