首页 > 解决方案 > 如何让用户输入的详细信息进入 python 文本文件中的新行?

问题描述

'''volunteerList.append([ [name], [coinType], [weight], [correct], "\n"])'''

上面的代码是我尝试过的代码,但输入的细节最终在同一行,并删除了最后一组输入的细节。

标签: python

解决方案


我不确定此示例中文件的位置,但您希望这样做不会覆盖文件:

name = "A"
coinType = "B"
weight = 99
correct = False

your_list = [ name, coinType, weight, correct]
text = "\n" + " ".join([str(x) for x in your_list]) 

with open("output.txt", "a") as f:
    f.write(text)

推荐阅读