2017-03-03 78 views
-1

所以我想能夠將這段代碼添加到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() 

這樣,多個人可以寫下他們的建議,而不會被下一個人所忽略。

我想它會自動添加到下面,而這似乎不是在其他線程中的情況。

+1

的[?你怎麼附加到文件(可能的複製http://stackoverflow.com/questions/4706499/how-do-you-附加到文件) – bejado

+0

它不是重複的。 –

+0

請確定你的問題與衆不同。 – bejado

回答

0

您需要更改wa,即:file = open("Suggestions.txt", "a")

相關問題