sorry for my bad English I would like to do an edit function for my project however I couldn't save the edited content into the txt file. Is there any advice?
def admin_edit_medic():
list_of_medicine = []
with open("medic.txt", "r") as medifile:
for line in medifile.readlines():
split = line.split(",")
list_of_medicine.append(split)
print(list_of_medicine)
print("\n"*2)
updated_details = []
data = str(input("Please input details to edit from the list: "))
edit = str(input("Please input new details to replace: "))
for medicine in list_of_medicine:
update = medicine.replace(data,edit)
updated_details.append(update)
print(list_of_medicine)
|txt file content|
Abacavir,20/5/2065,49.5,Treat HIV
Alemtuzumab,31/8/2045,977.9,Cure Leukhimia