[Solved] How to find and replace in 2 txt files with Python [closed]


I am converting the data in your MASTERIDS.txt to a dictionary. Key is the old id and value is the new ID. Then search for the dict for the new id using the value from OLDIDS.txt

Demo:

with open("PATH_TO_OLDIDS.txt", "r") as src:
    data = src.readlines()

d ={}
with open("PATH_TO_MASTERIDS.txt", "r") as toReplaceSRC:
    for i in toReplaceSRC.readlines():
        val = i.split()
        d[val[0].strip()] = val[1].strip()


for i in data:
toReplace = d.get(i.strip(), None)
if toReplace:
    print(i.strip(), " = ", toReplace)

Output:

12F  =  1FF
106  =  256
100  =  132

0

solved How to find and replace in 2 txt files with Python [closed]