Monday, October 31, 2005

Code to HTML

This python program replaces the special HTML characters (present in code) with their HTML codes. The listing below has been made from the program itself :)
print "Enter the file to read: "
name=raw_input()
in_file=file(name,"r")
buffer=in_file.read()
buffer=buffer.replace("&","&");
buffer=buffer.replace("\"",""");
buffer=buffer.replace("<","&lt;")
buffer=buffer.replace(">","&gt;")
out_file=file(name+".html","w+");
out_file.write(buffer);

No comments: