1
Good afternoon!
I would like a help in my project that seeks words (file: Variables.txt) inside of another file (Answers.txt) and marks if you find a word. But skipping a few sentences leaving blank the final text (Result.txt).
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()
Archives: -Variable:
oi
mundo
alo
tchau
Answers:
oi mundo
tchau vida solteira
ola meu amigos
mundo grande
Upshot:
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 equal to the expected result, however the bases are large and need to use the variables searching inside a txt like this in the code above.
has a
'
missing by code outside. Have it so only in question or have equal in your code ?– Isac
sorry, I was taking information from my pc to post here and I also accidentally took the ' .
– Gigliotti
a parallel tip - try to think about your variable names better - you have an "Arq" variable and a "file" variable, both representing different files. Nothing imprede that you call the variables "results, answers, words" - the program would be much easier to read.
– jsbueno