Skip to content

Instantly share code, notes, and snippets.

@abhiomkar
Created June 4, 2010 12:39
Show Gist options
  • Save abhiomkar/425362 to your computer and use it in GitHub Desktop.
Save abhiomkar/425362 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Author: Abhinay Omkar
# Title: Program to convert CSV Formatted data to HTML tables (without using any APIs)
def write2file(str, filename):
"""Write the content of 'str' to file - 'filename'"""
f = open(filename, 'w')
f.write(str)
f.close()
def main():
str = """<html>
<head>
<title> Raw strings converted to HTML table by Python</title>
</head>
<body>
<table border=1>
"""
print "Enter your input: "
while True:
try:
trow = ''
trow = trow + "\t\t<tr>\r\n"
for td in raw_input().split(';'):
trow = trow + "\t\t\t<td>" + td + "</td>\r\n"
trow = trow + "\t\t</tr>\r\n"
str = str + trow
except EOFError:
str = str + "\t</table>\r\n\t</body>\r\n</html>\r\n"
break
write2file(str, 'index.html')
print "Quiting. Bye!"
if __name__ == '__main__':
"""Program to convert CSV formatted data to HTML Tables"""
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment