Newline “\n” not Working when Writing a .txt file Python
问题 for word in keys: out.write(word+" "+str(dictionary[word])+"\n") out=open("alice2.txt", "r") out.read() For some reason, instead of getting a new line for every word in the dictionary, python is literally printing \n between every key and value. I have even tried to write new line separately, like this... for word in keys: out.write(word+" "+str(dictionary[word])) out.write("\n") out=open("alice2.txt", "r") out.read() What do I do? 回答1: Suppose you do: >>> with open('/tmp/file', 'w') as f: ..