I have a text file that I want to read in my cgi script that will appear with a new line in between each line but it is just coming up as one huge wall of text. I cant figure out where to put ‘\n’. I have tried multiple locations but none work. Here is my code.
cgitb.enable()
form = cgi.FieldStorage()
keyword = form.getvalue('keyword')
f = open('%s.txt' %keyword, 'r')
print 'Content-type: text/html\r\n\r'
print '<html>'
print '<title> keyword + "tweets" </title>'
print f.readlines()
print '</html>'
f.close()
By default, HTML treats newline characters as if they were whitespace. Convert those into
<br>elements, or wrap your text in a<pre>element, or make surewhite-spacehandling in CSS is appropriate.Also,
print f.readlines.join('\n')orprint f.read()(orprint f.readlines().join('<br>')if you go with the first choice); otherwise you should be getting the repr for the list.