I have a small file 5MB max size, having entries as below:
key_one = value_one
key_two = value_two
key_three = value_ three
.....
I need to iterate over each line and if the line matches certain condition, then I need to replace only the value part of the corresponding key in-place.
I have tried something like this:
def process_line():
with open("input_path") as file:
for each_line in file:
if each_line.startswith('some_key'):
new_value = "some_new_value"
file.write(each_line.replace(each_line.split("=")[1],new_value))
This isn't updating the line in the file. So I am doing something wrong. How do I update just the individual line in the file?