I am new to Python. I want to display MYSQL output using Python in an html file. I have the below code. However, it is not working and not actually giving me an error so I am not sure where I have gone wrong. I reviewed resources online but since I am not sure what I am looking for, not sure what to search for to fix the issue.
import mysql.connector
import webbrowser
conn = mysql.connector.connect(user='root', password='pswd#',
host='mysql',database='crm')
if conn:
print ("Connected Successfully")
else:
print ("Connection Not Established")
select_users = """SELECT * FROM users"""
cursor = conn.cursor()
cursor.execute(select_users)
result = cursor.fetchall()
p = []
tbl = "<tr><td>ID</td><td>Name</td><td>Email</td></tr>"
p.append(tbl)
for row in result:
a = "<tr><td>%s</td>"%row[0]
p.append(a)
b = "<td>%s</td>"%row[1]
p.append(b)
c = "<td>%s</td></tr>"%row[2]
p.append(c)
contents = '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Python Webbrowser</title>
</head>
<body>
<table>
%s
</table>
</body>
</html>
'''%(p)
filename = 'python.html'
def main(contents, filename):
output = open(filename,"w")
output.write(contents)
output.close()
main(contents, filename)
webbrowser.open(filename)
if(conn.is_connected()):
cursor.close()
conn.close()
print("MySQL connection is closed.")
What I am getting in the browser output is this.
Outcome I am looking for: I would like to display the table using pything/mysql in an html file. I am using Yahoo web hosting, I was able to use print("Hello World!") in an html file and get the output.
I would be very appreciative if anyone could point me in the right direction. Thank you.

% ('\n'.join(p))? Have a look to the"{} ".formatstring formatting notation