【发布时间】:2018-09-25 14:16:00
【问题描述】:
我有一个列表,它是附加项目的列表
if words[0] == "[" or words[len(words)-1] == "]":
if words in combinations1:
line.append(words)
当我尝试将此列表放入单个文件时,我只能获取列表中的最后一项。
我将其写入文件的代码是:
with open("file.txt", "w") as output_file:
output_file.write(str(line))
我需要将所有列表项写入文件。怎么做
【问题讨论】:
-
是否要将每个列表条目存储在新行中?
-
是的,我需要将每个条目存储到文件中的新行中
-
顺便说一句,
words[len(words)-1]与words[-1]相同。