Problems with HTMLgen tables

Martin Skøtt mskott at image.dk
Wed May 3 16:05:34 EDT 2000


Hi 
I'am trying to create an HTML table from a Python script using the
HTMLgen module. In the following lines you can see my test program,
the file i read, and the Python output when running it. Can you help
me solve the problem? (Red Hat 5.2, Python 1.5.1)

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")

netstats/data.dat:
200001 0.176920890808 0.0212049484253 0.198125839233
200002 274.809309959 21.8846673965 296.693977356
200003 453.032019615 30.9718132019 484.003832817
200004 243.101366997 19.5013065338 262.602673531

output when running script:
Traceback (innermost last):
  File "./html-table.py", line 29, in ?
    doc.write("data.html")
  File "/usr/lib/python1.5/site-packages/HTMLgen.py", line 188, in write
    f.write(str(self))
  File "/usr/lib/python1.5/site-packages/HTMLgen.py", line 274, in __str__
    s.append((bodystring % tuple(self.contents)))
  File "/usr/lib/python1.5/site-packages/HTMLgen.py", line 1560, in __str__
    self.body[i][j] = string.replace(self.body[i][j], '\n','<br>')
AttributeError: __setitem__
 
-- 
Martin Skøtt
mskott at image.dk

'In a certain sense, all decent programming languages are equally powerfull'
Dr. Alan Turing



More information about the Python-list mailing list