looping through a list

Hugh h.e.w.frater at cs.cf.ac.uk
Fri Apr 26 20:11:10 EDT 2002


I need help with a really simple algorithm that I can't get my head
around. I am looping through the list returned by a dcoracle2 execute
statement and need to add each item of data surrounded by some HTML
table tags to a string called text which I then pass to a page
generation method. At the moment I've got this:

result = c.fetchone()
  if (result != ""):
    i=0
    text = '<tr width = "80%" align = "center">'
    while (i != len(result)+1):
      i = i + 1
      text = text + '<td align = "center" valign =
"top">'+str(result[int(i)])  +'</td>'
    text = text + "</tr>"
    page.generate("","",sessionID,text)
  else:
    text = '<h4>No items found</h4>'
    page.generate("","",sessionID,text)


At the moment, it keeps saying list index out of bounds and I don't
know where I'm going wrong. I've tried all sorts of things in the
While statement and still can't get it going.

Hugh



More information about the Python-list mailing list