I have a python function that is supposed to receive:
- A file path
- A list of tuples with old value to find and new value to replace it.
The script is supposed to produce the same file modified with the tuple values (old to new). This is what I have tried so far:
def inplace_change(new_filename, old_string_new):
for old_new in old_string_new:
with open(new_filename, "rt") as fin:
with open(new_filename, "wt") as fout:
for line in fin:
fout.write(line.replace(old_new[0], old_new[1]))
I generally pass them alist of tuples like this:
[('PidFile=/path/xxx.pid',
'PidFile=/path/xxx.' + container_name + '.pid'),
('LogFile=/xx/log/nc_zabbix_agentd.log',
'LogFile=/xx/log/yyyy.' + container_name + '.log')
...]
Then a normal path where the file is.
I manage to replace only a tuple (single old string with new string) very easily, but when I have the list I can not get the logic to get this done. Any ideas?