-1

I am a novice coder and am not able to figure out my mistake here... I have a text that looks like this:

AAA,48,48,0,0,0,0,0,0,0,0,0
BBB,30,24,6,0,6,0,0,0,0,0,0

I want to write it to a HTML table. The code for that is this:

temp_lines=ftemp.readlines();
for line in temp_lines:
        tl,total,counter_pass,counter_kbug,counter_ubug,totbug,counter_kscr,counter_uscr,totscr,counter_kset,counter_uset,totset=line.split(",");

f.write("<tr><td height=\"30\"><a href="something".html>"+str(t1)+"</a></td><td height=\"30\">"+str(total)+"</a></td><td height=\"30\">"+str(counter_pass)+"</td><td height=\"30\">"+str(counter_kbug)+"</td><td>"+str(counter_ubug)+"</td><td height=\"30\">"+str(totbug)+"</td><td height=\"30\">"+str(counter_kscr)+"</td><td height=\"30\">"+str(counter_uscr)+"</td><td height=\"30\">"+str(totscr)+"</td><td height=\"30\">"+str(counter_kset)+"</td><td height=\"30\">"+str(counter_uset)+"</td><td height=\"30\">"+str(totset)+"</td></tr></center><br>");

I am getting this error:

TypeError: cannot concatenate 'str' and 'list' objects

I am explicitely converting every list object to string. Where am I going wrong?

1 Answers1

0

Consider the following:

For example, ' 1  2   3  '.split() returns ['1', '2', '3']

you are trying to do this str(['1', '2', '3'])

what happens when you try and concatenate:

"some html" + str(['1', '2', '3'])"
TypeError: cannot concatenate 'str' and 'list' objects

consider reading list manipulation or viewing a tutorial on this:

bascically, you need to extract the data from the list:

var_to_html = List_name[0] #position of the element to extract from the list
 now you can do "html" + var_to_html 
glls
  • 2,325
  • 1
  • 22
  • 39