Do you mean you want to format your output automatically in Python, i.e. wrapping it in appropriate HTML tags?
Or just do you mean save whatever comes out of your program into a file with a .html extension?

For appending to a file, just open it with append mode, i.e. filehandle = open("myfile.html", "a") Your question was way too vague. I can't read your mind, nor magically know what the output coming out of your program is like. You need to provide details.

Then you'll want to take each line of the output and search it. If it finds "FAILED" in the string, wrap the red-colour style tag around that line; if it finds "PASSED", wrap the green-coloured tag around it. Something like:

This is very basic of course, and if you're wanting to update the records by just appending new ones, I assume you'll need to open up the HTML, remove the ending body and html tags, add the records, and then reattach those tags.