x is not defined. You forgot the loop that would define it. This will create a generator so you will need to consume it with any:
KeyWord =['word', 'word1', 'word3']
if any(x in open('Textfile.txt').read() for x in KeyWord):
print('True')
This works but it will open and read the file multiple times so you may want
KeyWord = ['word', 'word1', 'word3']
file_content = open('test.txt').read()
if any(x in file_content for x in KeyWord):
print('True')
This also works, but you should prefer to use with:
KeyWord = ['word', 'word1', 'word3']
with open('test.txt') as f:
file_content = f.read()
if any(x in file_content for x in KeyWord):
print('True')
All of the above solutions will stop as soon as the first word in the list is found in the file. If this is not desireable then
KeyWord = ['word', 'word1', 'word3']
with open('test.txt') as f:
file_content = f.read()
for x in KeyWord:
if x in file_content:
print('True')