Search code examples
pythonhtmlloopsgenerator

Python for loop in HTML snippet


Does anybody have an idea how to rewrite this code snippet into more clean code? enter image description here

I tried to use a for loop but got this:

enter image description here

enter image description here


Solution

  • You can iterate through the rows_amount and add it like this.

    table_html+='<tr>'
    for row in schedule:
        for i in range(rows_amount):
            table_html+='<td>'+str(row[i])+'</td' #adding it to string