Writing string to a file on a new line every time

kaushik picture kaushik · May 27, 2010 · Viewed 743.2k times · Source

I want to append a newline to my string every time I call file.write(). What's the easiest way to do this in Python?

Answer

halfdan picture halfdan · May 27, 2010

Use "\n":

file.write("My String\n")

See the Python manual for reference.