0
I wanted that with this code I could go through my txt file and show all the same words (which is autonomy). I don’t know if it’s possible and the only way I can is to make a print(pesquisar_registro(file,word))
and so only shows the first word and shows nothing else.
file = 'aeronaves.txt'
word = input("Autonomia: ").lower()
def pesquisar_registro( arq, txt ):
nome = ""
with open( arq, 'r' ) as a:
for linha in a:
linha = linha.strip('\n')
if nome == "":
if txt in linha.split():
nome = linha
else:
registro = linha.split(',')
dic = { "Nome" : registro[0], \
"Autonomia" : nome, \
"Capacidade" : registro[1]}
return dic;
return None;
print (pesquisar_registro( file , word ))
my txt is saved this way:
123
boing747,123
123
boing567,567
345
boing456,567
Your code is riddled with errors, already tried to run it to see what happens?
– Guilherme França de Oliveira
I’ve fixed some misspelled indentations but yes it works but not only want the first word equal I wanted all the same words that appear in txt
– Filipe Ferreira