Python html格式所有选择表行 cursor.execute(““”从XYZ中选择[应用名称],[作业名称],[标签]) resultat=cursor.fetchall() 对于resultat中的行: html_code=“” 无标题文件

Python html格式所有选择表行 cursor.execute(““”从XYZ中选择[应用名称],[作业名称],[标签]) resultat=cursor.fetchall() 对于resultat中的行: html_code=“” 无标题文件,python,python-3.x,list,python-2.7,python-requests,Python,Python 3.x,List,Python 2.7,Python Requests,你的算法不好。在循环中,替换所有html代码,而不是添加新行 cursor.execute("""SELECT [APPL_NAME] ,[JOB_NAME],[LABE] FROM XYZ) resultat = cursor.fetchall() for row in resultat: html_code = """ <!d

你的算法不好。在循环中,替换所有html代码,而不是添加新行

cursor.execute("""SELECT [APPL_NAME] ,[JOB_NAME],[LABE] FROM XYZ)
         resultat = cursor.fetchall()
         for row in resultat:
                html_code = """
                 <!doctype html>
             <html>
             <head>
             <meta charset="utf-8">
             <title>Untitled Document</title>
             <body>
                 <table border='1'
                 <tr>
                     <th>Date</th>
                     <th>Count</th>
                     <th>Status</th>
                 </tr>
                 <tr>
                     
                     <td>{}</td>
                     <td>{}</td>
                     <td>{}</td>
                 </tr>
                 </table>
                 </body>
                 </html>""".format(row[0],row[1],row[3])
创建行:

cursor.execute("""SELECT [APPL_NAME],[JOB_NAME],[LABE] FROM XYZ""")
resultat = cursor.fetchall()
rows\u code=“”
对于resultat中的行:
行代码=行代码+“”“
{}
{}
{}
“”格式(第[0]行、第[1]行、第[2]行)
创建完整的html代码:

rows_code = ""
for row in resultat:
    rows_code = rows_code + """
        <tr>
             <td>{}</td>
             <td>{}</td>
             <td>{}</td>
        </tr>
    """.format(row[0],row[1],row[2])
html\u code=”“”
无标题文件

('row index of range index=3 len=3',)您好,谢谢您的代码。但我面临索引超出范围的问题。您能提供更多建议吗
html_code = """
    <!doctype html>
     <html>
     <head>
     <meta charset="utf-8">
     <title>Untitled Document</title>
     <body>
         <table border='1'
         <tr>
             <th>Date</th>
             <th>Count</th>
             <th>Status</th>
         </tr>
         {}
         </table>
         </body>
         </html>
""".format(rows_code)