converting a list into a HTML table in python
Question: Am having a text file where i read the content and assigning it to a variable.
I need to put the contents in a HTML table. As of now, i wrote a python
snippet to put the contents in a variable. How to convert it to a HTML table.
I need to loop through the file and assign the variable and update the data as
a field value in a table. How can i do it ? Help needed

My .txt file is

    
    
    34,52,l,ma,cgb,eta
    45,52,X,,lta,tox
    67,52,V,nm,,oyt
    

My code to read is :

    
    
    imp_auth = []
    asn_eng = []
    
    
    with open ("FR_list.txt","rt") as f:
     for line in f:
      (id,rel,sta,sev,ia,ae,iam,aem) = line.split(',')
      imp_auth.append(iam)
      asn_eng.append(aem)
    


Answer: You could use some of the available html templating engines and render the
template.

For example, by using [Jinja2](http://jinja.pocoo.org/docs/dev/) tempting
engine

    
    
    from jinja2 import Template
    table = """
    <table>
        {% for line in lines %}
        <tr>
            <td>{{ line[0] }}</td>
            <td>{{ line[1] }}</td>
            <td>{{ line[2] }}</td>
            ...
        </tr>
        {% endfor %}
    </table>
    """
    with open("FR_list.txt", "rt") as f:
        template = Template(table)
        t = template.render(lines=[line.split(',') for line in f])
        print(t)
        """
        <table>
            <tr>
                <td>34</td>
                <td>52</td>
                <td>l</td>
                ...
            </tr>
            ...
        </table>
        """
    

