[英]Adding Strings through input to .txt file in Python
我收到的輸出是“無”,而在 .txt 文件中已經有 3 個給定名稱,我想通過輸入再添加一個。
Add a new member: Solomon Right
None
Process finished with exit code 0
那是我的代碼:
newUserMember = input("Add a new member: ")
file = open("/Users/nikitalutsai/Downloads/members.txt", 'r')
content = file.readlines()
file.close()
content.append(newUserMember + "\n")
file = open("/Users/nikitalutsai/Downloads/members.txt", 'w')
content = file.writelines(content)
print(content)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.