I have a text file that includes a word like "test". Now what i am trying to do is using python i am opening that text file and search for that word. If the word exists then the python program should return exit code 0 or else 1.
This is the code that i have written that returns 0 or 1.
word = "test"
def check():
with open("tex.txt", "r") as file:
for line_number, line in enumerate(file, start=1):
if word in line:
return 0
else:
return 1
print(check())
output
0
what I want is I want to store this exit code in some variable so that i can pass this to a yaml file. Can someone guide me here how can i store this exit code in a variable? thanks in advance
return 0immediately when the word is found in a line, butreturn 1only at the end when the whole file has been read without finding the word.