所以我希望能够将这段代码添加到Suggestions.txt中,而不是替换现有内容(即现有内容下面的两行)
input1 = input("What is your name?: ")
input2 = input("What is your suggestion for another issue to be solved: ")
input3 = input("Do you know how to solve this issue? If not press enter: ")
input4 = input("What keywords would the user need to use to access the solution? \n Press enter to leave blank: ")
file = open("Suggestions.txt", "w")
file.write("Name: " +input1 + "\n")
file.write("Suggestion: " +input2 + "\n")
file.write("Solution: " +input3 + "\n")
file.write("Keywords: " +input4 + "\n")
file.close()
这样,多人可以写出他们的建议,而不会被下一个人压倒。
我希望它能自动添加到下面,但在其他帖子中似乎并非如此。
答案 0 :(得分:0)
您需要将w
更改为a
,即:file = open("Suggestions.txt", "a")