I have a text file with list of IDs. I want to iterate through the lines of that file, checking if the IDs appear in the lines of a second file, "extra_lines.txt". If the ID is present in a line of the second file, I want to print that whole line to output.txt. However, only the line containing the final ID is being printed. What am i doing wrong?
outfile = open("output.txt", "a")
def checkLine(ID):
with open("extra_lines.txt") as f:
for line in f:
if ID in line:
outfile.write(line)
for ID in open("IDs.txt", "r"):
checkLine(ID)