Ari Madian Ari Madian - 7 months ago 10
Python Question

How to write a variable to a file on a new line every time?

I am trying to put a variable in to a file and have it go on a new line every time. For example,

file.write(variablehere)


This has already been asked with how to write it as a string like
file.write(stringhere)
and to do it that way, you just do "/n" but that doesn't work with variables for some reason.

I've tried this as:

file.write(variable/n)
file.write('variable/n')
file.write(variable + '/n')


None of those worked. Thanks for the help!

Answer

You are using a forward slash /n and you need to use a backslash \n.

Comments