簡體   English   中英

如何讓用戶輸入的詳細信息進入python文本文件中的新行?

[英]How do I get the details entered by the user to go onto a new line in the text file in python?

'''volunteerList.append([ [名稱], [coinType], [重量], [正確], "\\n"])'''

上面的代碼是我嘗試過的代碼,但輸入的詳細信息最終在同一行上,並刪除了輸入的最后一組詳細信息的部分內容。

我不確定此示例中文件的位置,但您希望這樣做不會覆蓋文件:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM