I have a .csv file divided in four different columns, and I would write a search function in python that gives to me the print of a particular line of the document, but to do that I made some lists to get a thickest search...that's because if I simply open the csv document, the search could find similar word also inside - for instance - inside a name or other words (so, if I try to search 'App' because it is in a column, the result could be the exact line for the word 'App' but also for the name - randomly given for instance - 'Applebaum'... and I don't want that). In my script, I use to give a variable for input() but I need to use tkinter so I think I have to use an Entry instead input()... Finally, I would that if the entry is not equal in the csv file (matching the lists), a messagebox give a message for is missing found.
So, I tried:
import csv
from tkinter import messagebox
def search_parameter():
accepted_word_for_foods = ['bread', 'jam', 'cake', 'wakamole', 'tomato', 'pear']
accepted_word_for_drinks = ['water', 'juice', 'milk', 'tea' ]
accepted_word_for_colors = ['red', 'brown','blue']
param = input('Insert here your param...\n')
csv_f = csv.reader(open('random_list_example.csv', 'r'))
for row in csv_f:
if param in row[0] == accepted_word_for_foods:
print(row)
if param in row[1] == accepted_word_for_drinks:
print(row)
if param in row[2] == accepted_word_for_colors:
print(row)
if param != accepted_word_for_foods:
messagebox.showwarning(title='Not found', message='Param not present or bad digit')
if param != accepted_word_for_drinks:
messagebox.showwarning(title='Not found', message='Param not present or bad digit')
if param != accepted_word_for_colors:
messagebox.showwarning(title='Not found', message='Param not present or bad digit')
search_parameter()
Obviously, it doesn't work! I tried also different combinations (if params == accepted_words_for_foods in row[0]...etc etc...), but I think the problem is in the way I refer to the list, but I don't really understand how to do.