如何打印一个fetchone()函数但却得到NoneType错误?Sqlite3公司

2024-09-30 20:31:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图打印fetchone()值,但它只是给了我一个错误'NoneType' object is not iterable,有人知道为什么吗

这是我的密码:

def viewemaillook():
        global realusername
        global realpassword
        viewemail = input("Would you like to see/change your email")
        if viewemail == "y" or viewemail == "yes":
            c.execute("SELECT email, * FROM stuffToPlot WHERE username = ?  and password = ?", (realusername,realpassword,))
            grab = c.fetchone()
            for i in grab:
                print(i)
        elif viewemail == "n" or "no":
            print("Okay")
        else:
            print("Invalid option")
            viewemaillook()
    viewemaillook()
else:
    print("Not a valid option")
    change()
change()

Tags: oremail错误changeglobalelseoptionprint
1条回答
网友
1楼 · 发布于 2024-09-30 20:31:22

如果查询没有找到任何结果,则fetchone()将返回None。当你尝试在grab上循环,它等于None你得到了错误。请先检查grab中是否有结果。你知道吗

相关问题 更多 >