Iv'e written this code that generates an html list from a MySQL query. I'm able to write it to the index.html file but it overwrites everything in it. How can I get this list to appear at the point that I want it to inside the index.html file without overwriting the entire index.html file?
Here's the code that generates the html output and writes it to the file:
import MySQLdb
import time
import HTML
db = MySQLdb.connect(
host=" ",
user=" ",
passwd=" ",
db=" ")
c = db.cursor()
c.execute("SELECT `name`,`symbol`,`last`,`diff` FROM `nyse_100`")
result = c.fetchall()
result = list(result)
htmlcode = HTML.list(result)
with open("../index.html", "w") as my_file:
my_file.write(htmlcode)
The output is :
<UL>
<LI>('Exxon Mobil Corp.', 'XOM', '102.59', '-0.06')
<LI>('International Business Machines Corp.', 'IBM', '182.56', '0.00')
<LI>('Chevron Corp.', 'CVX', '127.11', '-0.15')
<LI>('General Electric Co.', 'GE', '27.01', '-0.03')
<LI>('Procter & Gamble Co.', 'PG', '79.62', '-0.02')
</UL>