简体   繁体   中英

I want to be able to delete a specific line in this text file

I have the following code which must delete a specific line in the 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)

Here is the problem, i dunno what to put here:

if start == "delete":
    notetodelete = input("Type the note you want to delete \n")
f.close()

Search for the note you want to delete using the string.index() method. You can then use string.replace() method to get your string after it gets deleted

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM