python – Writing string to a file on a new line every time
python – Writing string to a file on a new line every time
Use n:
file.write(My Stringn)
See the Python manual for reference.
You can do this in two ways:
f.write(text to writen)
or, depending on your Python version (2 or 3):
print >>f, text to write # Python 2.x
print(text to write, file=f) # Python 3.x
python – Writing string to a file on a new line every time
You can use:
file.write(your_string + n)