I am trying to make a function that will extract data from a .txt in the format 'Sample 1: 1, 2, 7' and then replace the first value, pushing the other two along and removing the last one. When I input '4', I would expect the following output: 'Sample 1: 4, 1, 2', however the data does not change. I am not searching for a value, as the code iterates through each line in the file and changes a specific part of it. It does not replace the whole line.
Here is my code:
f = open("task3.txt")
lines = f.readlines()
print(lines)
for i in lines:
splitlines = i.split(":")
print(splitlines)
splitnums = splitlines[1].split(", ")
print(splitnums)
for i in splitnums:
i = int(i)
edit = input('Would you like to edit this entry?')
if edit == "Yes":
valueNew = input("Which new value would you like to add?")
del(splitnums[2])
splitnums.append(splitnums[1] + "\n")
splitnums[1] = splitnums[0]
splitnums[0] = valueNew
print(splitnums)
numstring = ''.join(splitnums)
splitlines.append(splitlines[1])
splitlines[1] = ": "
newval = ''.join(splitlines)
newval = str(newval)
i = str(i)
print(newval)
i.replace(i, newval)
else:
print("Okay.")
f.close
Also, the text in the file is not replaced. Thanks for any help you can offer.