xadd = open('x.txt', 'w', encoding="utf-8") hha = [ 'j', 'a', 's', 'o', 'n', '\\n', 'b', 'r', 'o', 'w', 'n'] a = ''.join(hha) xadd.write(a) xadd.close() File's output is jason\nbrown. I can assume that the problem is with a variable because when I do it normally, without join file has newlines. Can someone explain me why is that not working and give me the solution for this problem?
\nis escaped in your list to\\n\nin your list or just do"".join(hha).replace("\\n", "\n")a = jason\nbrownis not valid in Python.