Reputation: 1
I am using python to search a CSV file for a certain variable, but I want it to be more specific. What I mean is, is that if I am searching a CSV file for, say, the word "dog". If I input the word "do" into it, as it is part of "dog" it will accept it. How can I change this?
a = input("Enter your e-mail: ")
b = input("Enter your password: ")
import csv
c = csv.reader(open('Address Book.csv'))
for row in c:
if a in (row[5]):
if b in (row[6]):
print ("Your details are:")
print ("First Name:", row[0])
print ("Surname:", row[1])
print ("House Number and Street Name:", row[2])
print ("Town/City:", row[3])
print ("Postcode:", row[4])
print ("E-mail:", row [5])
print ("Password:", row [6])
else:
print ("Password is incorrect")
Upvotes: 0
Views: 86
Reputation: 377
Instead of checking that a
and b
are in your row fields, you should check if the variables are exactly equal using:
for row in c:
if a == row[5]:
if b == row[6]:
print("...")
Thus, if you input a
as do
and row[5]
is dog
, the equality condition would fail and the code won't be executed.
Upvotes: 1