conn = MySQLdb.connect (host = "localhost", user="root", passwd="xxxx", db="xxxxx")
cursor = conn.cursor()
cursor.execute ("SELECT * FROM pin WHERE active=1")
while (1):
row = cursor.fetchone()
st = str(row[2])
pin = str(row[1])
order = str(st)+str(pin)
if row == None:
break
sendSerial(order)
conn.close()
为什么st=str(行[2])变成错误? 如何将数据库中的行检索到变量中?
谢谢你的回答。
st = str(row[2])
是一个错误,因为cursor.fetchone()
在没有更多行时返回None
。使用以下方法之一修复它:
或者
或者
相关问题 更多 >
编程相关推荐