I have a .txt file in the same folder as this .py file and it has this in it:
.txt
.py
cat\\n dog\\n rat\\n cow\\n
How can
Open the file in append mode and write a new line (including a \n line separator):
\n
with open(filename, 'a') as out: out.write(var + '\n')
This adds the line at the end of the file after all the other contents.