为什么我的Python元组只存储第一个值?

时间:2016-09-19 16:04:01

标签: python mysql tuples

我在我的python脚本中存储了一个元组中的mysql查询。我在脚本中有一个raw_input变量,我想检查它们是否与元组中的匹配。

curs.execute("""SELECT username, id FROM employees WHERE gid!=4""")
rows=curs.fetchall()
db.close()

uname = raw_input('Type the username for the new device: ')

for row in rows:
  user = row[0]
  empid = row[1]

  if user == uname:
    print 'User ' + uname + ' found...'
  else:
    print 'Not Found'

仅当我输入第一个员工的用户名时才有效。任何其他员工都会返回“未找到”

我注意到,如果我删除raw_input行,并删除if语句并添加

for row in rows:
  user = row[0]
  empid = row[1]
  print user

它打印所有值

1 个答案:

答案 0 :(得分:0)

根据我的假设,您可能会采用更好的方法。

当你可以简单地将它添加到// Import firebase if the project was created using the Aurelia-CLI // If you're using the Aurelia Esnext-Skeleton, you don't have to import firebase import firebase from 'firebase'; export class App { constructor() { this.some_ref = firebase.database().ref('some_path'); } } 子句时,Python中的循环没有理由搜索用户。

WHERE

如果找到,将返回用户名。否则'找不到'。