I have a for loop iterating through my file, and based on a condition, I want to be able to read the next line in the file.I want to detect a keyword of [FOR_EACH_NAME] once I find it, I know that names will follow and I print each name. Basically Once I find the [FOR_EACH_NAME] keyword how can I keep going through the lines.
Python code:
file=open("file.txt","r")
for line in file:
if "[FOR_EACH_NAME]" in line
for x in range(0,5)
if "Name" in line:
print(line)
Hi everyone, thank you for the answers. I have posted the questions with much more detial of what I'm actually doing here How to keep track of lines in a file python.
next(file)to get the next line. Note that in doing this, you're advancing the same iterator as your for loop is using, so it will miss any lines you get in this way.