Writing string to a file on a new line every time Writing string to a file on a new line every time python python

Writing string to a file on a new line every time


Use "\n":

file.write("My String\n")

See the Python manual for reference.


You can do this in two ways:

f.write("text to write\n")

or, depending on your Python version (2 or 3):

print >>f, "text to write"         # Python 2.xprint("text to write", file=f)     # Python 3.x


You can use:

file.write(your_string + '\n')