Problems with HTMLgen tables

Martin Skøtt mskott at image.dk
Thu May 4 08:19:50 EDT 2000


Shae Erisson <shapr at uab.edu> writes:

> It's just a workaround, but I hope it helps.

Thanks Shae it worked perfectly (strange the code i posted was very
inspired by an example from an older Linux Joournal article).
With almost the same code I have now encountered a new
problem. Instead of reading a file the data for the table comes from
an PostgreSQL database, the query works fine and data is returned as a
list of lists. But when I try to place it in a table HTMLgen makes
trouble can some body help me? The code and result of running comes
here:
#!/usr/bin/env python
import string, HTMLgen, _pg
data = _pg.connect('bog_depot', 'localhost')
fila = data.query("select * from test").getresult()
doc = HTMLgen.SimpleDocument(title='Interface statistik for ppp0')
table = HTMLgen.Table()
tabel = []
doc.append(table)
for line in fila:
    tabel.append(line)
    print line
table.body = tabel
doc.write("data-pg.html")

With the following response:
('ping', '05-04-2000') <-- Query result gets printed to stdout to.
Traceback (innermost last):
  File "./html-pg-tabel.py", line 21, in ?
    doc.write("data-pg.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