import os;f_in = open("hello.cpp", "r")print "file name is: ", f_in.namef_out = open("hello2_v2.html", "w")f_out.write("<html>\n<body>\n<pre>\n")for line in f_in: #line = line.strip('\n') line = line.replace("<", "<") line = line.replace(">", ">") print line, #f_out.write(line+"\n") f_out.write(line)f_out.write("</pre>\n</body>\n<html>")f_in.close()f_out.close()
import os;f_in = open("hello.cpp", "r")print "file name is: ", f_in.namef_out = open("hello_table.html", "w")f_out.write("<html>\n<body>\n")# add formf_out.write("<form id=\"comment_form\" style=\"display:none\"><textarea name=\"comments\"></textarea><br \><input type=\"submit\"></form>")f_out.write("<table>\n<tbody>\n")line_num = 0for line in f_in.readlines(): line_num = line_num + 1 line = line.strip('\n') line = line.replace("<", "<") line = line.replace(">", ">") f_out.write("<tr onclick=\"document.getElementById(") f_out.write("\'comment_form\'") f_out.write(").style.display=\'block\';\"><td> ") f_out.write(str(line_num) + " ") f_out.write("</td><td>") f_out.write(line+"\n") f_out.write("</tr></td>")f_out.write("</tbody>\n</table>\n</body>\n<html>")f_in.close()f_out.close()