Problems with HTMLgen tables
Thomas A. Bryan
tbryan at python.net
Thu May 4 08:37:23 EDT 2000
"Martin Skøtt" wrote:
> Can you help me solve the problem? (Red Hat 5.2, Python 1.5.1)
Yes.
> html-table.py:
> #!/usr/bin/env python
> import string, HTMLgen
> data = 'netstats/data.dat'
> fil = open(data, 'r')
> fila = fil.readlines()
> doc = HTMLgen.SimpleDocument(title='Interface statistik for ppp0')
> table = HTMLgen.Table()
> table.body = []
> doc.append(table)
> for line in fila:
> inf = string.strip(line)
> table.body.append(inf)
>
> doc.write("data.html")
The problem is in the line that reads
inf = string.strip(line)
You probably want
inf = string.split(line) # this makes the most sense to me
or
inf = [string.strip(line)]
You could also fix the problem at the point where you
append to the table.body.
table.body.append([inf])
The table.body is a list of lists. Each list in
table.body is a (table) row. Each element of the nested
lists is a (table data) column in that row.
You were appending plain strings returned by string.strip.
---Tom
More information about the Python-list
mailing list