【发布时间】:2015-06-21 04:17:23
【问题描述】:
因此,在阅读了许多回答相同问题的实例之后,我仍然陷入困境。为什么这个函数不是每次都换行?:
def addp(wrd,pos):
with open('/path/to/my/text/file', 'w') as text_file:
text_file.write('{0} {1}\n'.format(wrd,pos))
看起来\n 应该可以解决问题。我错过了什么吗?
我正在运行 Ubuntu 15.04
【问题讨论】:
-
您使用了错误的模式。你需要使用
'a'(append),而不是'w'(写)。
标签: python newline file-writing