name email phonenumber
eric example@gmail.com 01381031
tuna tuna@gmail.com 1571051
above is the personal_details.txt
def personal(userid):
print("Modify personal details")
newemail = input("Enter your new email: ")
newphone = input("Enter your new phone:")
with open("personal_details.txt", "r+") as file:
for line in file:
line = line.split()
if userid == line[0]:
file.seek(0)
file.write(" " + newemail + " " + newphone)
file.truncate()
I am creating profile system which users can modify the details. I wanna overwrite the text in line[2] and line[3] of the files but it keeps overwriting the whole files. Im quite new to python so I really need some helps to figure out this problem.