I have a large file with following format:
Good day, Jenny. (pending)
Good day, Tommy.
Good day, Henry.
Good day, Mary.
Good day, Austin.
Good day, Eason.(pending)
Good day, Eric.
.....
What I need to do is to print the line that contains the word 'pending' and its following three lines. However, I just know how to print the line that contains the word 'pending'. Some one can help? Here is my simple code:
word = 'pending' with open ('1.txt', 'r') as inf: for line in inf.readlines(): #line = line.split() if word in line: print(line) Thanks for your help.
readlinesto get all the lines