0

I am trying to write python code where I write to a fileand for each f.write. I want to make it write to a new line. I thought \n would do it. But right now everything is being written to one line. What am I doing wrong ?

Code (localtime, sum and value are variables)

f = open('/var/www/html/index.html','w') f.write("<font size='35px'>"+sum+"</font>") f.write('\n'+localtime) f.write('\n Sist oppdatert '+value) f.close() 
6
  • 2
    Are you talking about a new line in the file or an actual new line break in the HTML document? Commented Jan 3, 2016 at 19:32
  • Tip: Please provide minimal working examples (stackoverflow.com/help/mcve) next time you ask a question on SO. Commented Jan 3, 2016 at 19:33
  • There is a newline \n being correctly appended. What's going wrong for you? Commented Jan 3, 2016 at 19:33
  • In the HTML document. So when I view it from the browser it will give me a new line. Commented Jan 3, 2016 at 19:34
  • And please use a different variable name other than sum - it's a built in function. Commented Jan 3, 2016 at 19:34

1 Answer 1

2

Use line breaks <br/> for html line breaks:

f = open('/var/www/html/index.html','w') f.write("<font size='35px'>"+sum+"</font>") f.write('<br/>'+localtime) f.write('<br/> Sist oppdatert '+value) f.close() 
Sign up to request clarification or add additional context in comments.

Comments