Reputation: 111
I wrote this script to construct a very basic web page from text input. It goes line by line indefinitely until the user types 'q' on the last line and hits enter. The problem is that if I input a tab or some spaces up front, they are not written to the final html file. I have included two methods in this script, they both give the same output... The second is commented out
from sys import argv
script, file = argv
boom = open('%s.html'% file,'w')
header = """<html>
<head>
<style>
body {background-color:black; color:white;}
</style>
</head>
<body>
"""
footer = """</body>
</html>
"""
boom.write(header)
#lines = ''
#lines = list(lines)
while True:
line = raw_input(">")
if line != "q":
# lines.append('%s<br>\n' % line)
boom.write('%s<br>\n' % line)
else:
# string = ''.join(lines)
# print string
# boom.write(string)
boom.write(footer)
boom.close()
exit(0)
Upvotes: 0
Views: 566
Reputation: 69022
Have you tried looking at the source of the file? The spaces and tabs are written to the file as intended, your problem is that whitespace is largely ignored when html is parsed. If you want it preserved, you could replace spaces with
, or enclose the section in a <pre>
block.
Upvotes: 4