Aug-02-2021, 06:21 PM
Thank you, deanhystad for your code and explaining me why my code was not working. Your code works well and from your code I also understood how to report the files with a match score better than some threshold value.
I have just one last question. What about if I want to search for more than one string, to improve my matching? I tried
I have just one last question. What about if I want to search for more than one string, to improve my matching? I tried
keywords=["john", "mary"] #I know that there is one text file talking about john and mary best_match = (None, 0, None) # Remember the best match. for file in os.listdir('C:/Users/mydirectory'): with open('C:/Users/mydirectory/'+file) as f: words = set(f.read().split()) match = process.extractOne(keywords, words, scorer=fuzz.token_set_ratio): if match[1] > best_match[1]: best_match = (match[0], match[1], file) print(best_match)but I obtained the error "expected string or bytes-like object".