[英]I want to remove a line in a text file by asking the user to input an attribute in the line to delete it
[英]I want to be able to delete a specific line in this text file
我有以下代碼必須刪除文本文件notes.txt
的特定行:
f = open("notes.txt","r+")
notestext = f.read()
print("NOTES:")
print(notestext)
enter = input("Press enter to add or change notes \n")
print("Type delete to delete a note or add to add a note")
start = input()
if start == "add":
notetoadd = input("Type your note to add \n")
f.write("\n")
f.write(notetoadd)
這是問題,我不知道該放什么:
if start == "delete":
notetodelete = input("Type the note you want to delete \n")
f.close()
使用 string.index() 方法搜索要刪除的筆記。 然后你可以使用 string.replace() 方法在它被刪除后獲取你的字符串
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.