I'm having issues getting the results i'm looking for (obviously...) I am trying to read a text file, then parse it looking for a string, If it sees that string replace text on the NEXT line. This is what I have so far:
import fileinput import sys x = 0 value = "car" with fileinput.input(files="testfile.txt") as file: for line in file: if x == 1: line = line.replace("car", "truck") sys.stdout.write(line) print("Triggered") x = 0 if value in line: x = 1 print("Activated") fileinput.close()My textfile has the following: (just as a test)
Output:This is line 1
This is line 2
Check
Changes
apple
Apricot
grape
car
car
truck
Am I going about this the wrong way or am I close just missing something?