在我的代碼中,當raw_input
相等時,它必須打印相應的單個值,但在這裏我得到了這兩個值。從mysql中檢索相同的值
如果鍵入raw_input
是自行車,它同時顯示自行車和汽車,而不是僅自行車
請幫幫忙,我只得到一個價值
數據庫:
bike
car
編碼:
import MySQLdb
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="root", # your username
passwd="mysql", # your password
db="sakila") # name of the data base
cursor = db.cursor()
# execute SQL select statement
cursor.execute("SELECT A1 FROM adarsh1")
name = raw_input("What's your name? ")
keywords1=[]
for i in cursor.fetchall():
keywords1.append(i[0])
if name in keywords1:
print i[0]