Skip to main content

Posts

Showing posts from February, 2026

Find and replace multiple text in a file using Python

Here is a code which shows how to find and replace multiple text in a file using Python: search_text_1 = "36419" search_text_2 = "250847" search_text_3 = "2764437" search_text_4 = "OOGGT" i=1 for j in range(2000):     with open('C:\\Users\\Original\\'               'source_filename.txt', 'r') as file:         data = file.read()         GS = int(search_text_1) + i         data1 = data.replace(search_text_1, str(GS))     with open('C:\\Users\\Original\\Champ\\'               'E_EI4.20213.024.35.X1.243_' + str(i) + '.txt', 'w') as file:         file.write(data1)     with open('C:\\Users\\Original\\Champ\\'               'E_EI4.20213.024.35.X1.243_' + str(i) + '.txt', 'r') as file:         data = file.read()         N9 = int(search_text_2) ...