我试图将列表保存到文本文件中,每个句子占一行。但是为什么这些代码对我无效呢?有人知道吗?谢谢。
import codecs
text = ["good morning", "hello everybody"]
for texts in text:
file = codecs.open("newlinetest.txt", "w", "utf-8")
print texts
file.write(texts + "\n")
file.close()
'w'
) 打开会覆盖现有内容,因此仅会有一行。 - cdarke