Home > Blockchain >  Find word in a csv file
Find word in a csv file

Time:02-20

I´m new into python, so I apreciate any help. I´m trying to develope a code that can search for a specific word in a csv file, but I don´t why he doesn´t recognize a word that I know it is in the program. I'm always getting "Não encontrei".

My code:

#Definir perfis

def pilar():
    pilar = input("Perfil do pilar:")
    csv_file=csv.reader(open(r"C:\Users\tomas\Documents\ISEP\5º Ano\TESE\PROGRAMA\PERFIS.csv"))
    
    for row in csv_file:
        if pilar in csv_file:
            print("Pilar: ", pilar)
        else:
            print("Não encontrei")
pilar()

CodePudding user response:

Can you try:

search_list = []
for row in csv_file:
    if pilar in csv_file:
        search_list.append(pilar)

if pilar in search_list:
    print("Pilar: ", pilar)
else:
    print("Não encontrei")
    

CodePudding user response:

Code:

def pilar(): pilar = input("Perfil do pilar:") csv_file=csv.reader(open(r"C:\Users\tomas\Documents\ISEP\5º Ano\TESE\PROGRAMA\PERFIS.csv")) search_list = [] for row in csv_file: if pilar in csv_file: search_list.append(pilar) else: print("Não encontrei") pilar()

  • Related