Good afternoon!
I would like some help in my project that looks for words (file: Variables.txt) within another (Answers.txt) file and makes the markup Find a word. But by jumping some sentences leaving the final text (Result.txt) blank.
I reduced the size of the bases to facilitate understanding.
Code:
for i in range(1,23):
arquivo = open('\Variaveis.txt', 'w')
with open('\Respostas.txt') as stream:
with open('\Resultado.txt') as arq:
palavras = arq.readlines()
for line in stream:
for word in palavras:
if word.lower() in line.lower():
a = (line.strip(), '¬', word + '\n')
arquivo.writelines(a)
print(a)
break
arquivo.close()
Files: -Variables:
oi
mundo
alo
tchau
Answers:
oi mundo
tchau vida solteira
ola meu amigos
mundo grande
Result:
oi mundo¬mundo
tchau vida solteira¬tchau
Expected result:
oi mundo¬oi
tchau vida solteira¬tchau
ola meu amigos¬ola
mundo grande¬mundo
Note: I was running the project writing the variables inside the code and it worked the same as the expected result, but the bases are large and I need to use the variables searching within a txt like this in the above code.