Hello, I'm new to Python, and I'm working on a to-do list. I'm wondering how to remove a line from a .txt file. I know how to add to a .txt file, but not remove. This is my code:
"""To Do List"""
print("Welcome back .")
user_list = []
with open("user_data.txt", encoding="utf-8") as f:
user_data = f.read()
user_list.append(user_data)
while True:
user_input = input("What do you want to do? >>")
if user_input == "stop":
break
elif user_input == "add":
print(f"Your current To Do List is {user_list}.")
user_add = input("What will you add to your To Do List? >>")
user_list.append(user_add)
with open("user_data.txt", "a", encoding="utf-8") as f:
f.write(user_add + '/n')
print(f"Your new To Do List is {user_list}")
elif user_input == "remove":
print(f"Your current To Do List is {user_list}.")
user_remove = input("What will you remove from your To Do List? >>")
user_list.remove(user_remove)
print(f"Removed {user_remove} from your To Do List")