【问题标题】:SQLite query returning falseSQLite 查询返回 false
【发布时间】:2019-03-21 21:57:21
【问题描述】:

所以对于我的项目,我试图让用户在文本框中输入一些内容,如果它等于存储在数据库中的内容,那么它将告诉他们这是真的。然而,目前即使输入了正确的内容,它也会返回 false。这是获取答案、返回和比较的部分的当前代码:

    def submit():
        answerA=entry_A.get()
        answerB=entry_B.get()
        answerC=entry_C.get()
        answerD=entry_D.get()
        answerE=entry_E.get()
        answerF=entry_F.get()
        print(answerA,", ",answerB,", ",answerC,", ",answerD,", ",answerE,", ",answerF)

        labelA=cursor.execute\
        ("select labelA from diagramLabels where diaName == 'plantCell'").fetchall()
        con.commit()
        if labelA == answerA:
            print("Answer A is correct")
        else:
            print("Answer A is false")

And this is the result it gives in Idle, along with what's in the database

请告诉我我做错了什么。

【问题讨论】:

    标签: python sql tkinter sqlite python-3.4


    【解决方案1】:

    您应该使用fetchone() 而不是fetchall()
    fetchall() 返回多行(例如:(('nucleus',),)),而fetchone() 只会返回一行。 然后你会得到这样的东西:('nucleus',)
    那你可以和labelA[0] == answerA比较一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-27
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多