I have a text file where i have numbers and names listed. each number belongs to a specific name, and they belong on the same line. the content of the file, looks like this:
Kari 98654321
Liv 99776655
Ola 99112233
Anne 98554455
Jens 99776612
Per 97888776
Else 99455443
Jon 98122134
Dag 99655732
Siv 98787896
(NOTE* the names and numbers are seperated by a new line, it just pastes everything on the same in here for some reason) Lets say i choose "Else" as the chosen name, i want to be able to update the file and change the chosen person's number with a new chosen number
I am not that experienced in python, so i am sturggling quite much with finding solutions for this problem, but ive tried using .replace(), .readline() and other functions to replace the content with something else, but i just keep replacing the entire file
import os
def endreNummer():
with open("hei.txt", "a+"):
endreNummer()
the expected output if i chose "Kari" as name, and "1881" as the new number. the output would look like this:
Kari 1881
Liv 99776655
Ola 99112233
Anne 98554455
Jens 99776612
Per 97888776
Else 99455443
Jon 98122134
Dag 99655732
Siv 98787896