无法使用pymysql cursor.fetchall调用str对象

时间:2019-04-29 13:47:37

标签: python mysql database pymysql

我正在尝试查看用户输入的内容是否与我从php数据库检索的字符串匹配。我已经检索了数据,并且可以使用print(i [random])打印它,但是当我尝试将用户的输入与englishWord = input(“ type answer”,i [random])语句进行比较时,出现此错误TypeError:“ str”对象不可调用

conn = pymysql.connect(host="myhost",user="myname",password="mypassword",db="mydb")

myCursor = conn.cursor()

query = """SELECT russianWord, englishWord FROM words WHERE wordID = 1;"""

myCursor.execute(query)

records = myCursor.fetchall()

random = randint(0,1)

for i in records:
    if random == 0: 
        englishWord = input("type answer", i[random])
    else:
        russianWord = input("type ander", i[random])

0 个答案:

没有答案