I have a file "xyz.txt" and I am writing a python script to replace a string in a particular line. So essentially I have a string which says
x == in one line which I want to replace with x == 10.
In another line I have xx == 5 which I don't want to replace.
When I use the command -
for line in fileinput.input([filename],inplace=True):
line.replace(old string, new string)
where,
old string = "x =="
new string = "x == 5".
This ends up replacing the other line that has xx == 5 that I don't want to modify.
What would be the best way to just modify that one particular line with x ==
rather than modifying all the lines with "x == " string present in them?