Ari Madian Ari Madian - 2 years ago 51
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,


This has already been asked with how to write it as a string like
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')

None of those worked. Thanks for the help!

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download