G'day everyone,
I've read all over the place on this topic, but am yetI want to find a solution that works for me. Here's what I've got so far. As you can see, it will search thea CSV file, and print either TrueTrue or FalseFalse, depending on whether or not it findsI found the usernamestring. However, I'm running into the problem whereby it will return a false positive if it finds the usernamestring embedded in a larger string of text. EgE.g.: It will return TrueTrue if usernamestring is foofoo and the term foobarfoobar is in the CSV file. I need to be able to return exact matches.
username = input()
if username in open('Users.csv').read():
print("True")
else:
print("False")
From other questions on here, I've looked at using mmapmmap, rere and csvcsv module functions, but I haven't got anywhere with them. I've posted the above code to show the sort of level I'm currently at with Python (very much a beginner). Any points in the right direction would be greatly appreciated! If you need any further detail, just let me know.
EDIT: I thought I'd add an example ofHere is an alternatealternative method I've been pursuing. Again, I'm a beginner and am using this particulat syntax for the first time :)
import re
import csv
username = input()
with open('Users.csv', 'rt') as f:
reader = csv.reader(f)
for row in reader:
re.search(r'\bNOTSUREHERE\b', username)