我正在尝试打印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()
答案 0 :(得分:1)
如果您的查询未找到任何结果,则fetchone()
将返回None
。当您尝试循环等于grab
的{{1}}时,您将收到错误消息。请先检查None
是否有结果。