Python TypeError:参数类型为';非类型';不适用于mysql.connector
我尝试使用这个函数:当用户输入任何用户名时,如果用户名在数据库中,它将打印“标志”,如果不在数据库中或用户不输入任何内容,它将“不在这里打印”, 因此,当我运行这段代码并尝试输入一些datbase中没有的用户名,并尝试将其保留为空白时,我发现了这个错误Python TypeError:参数类型为';非类型';不适用于mysql.connector,python,mysql,Python,Mysql,我尝试使用这个函数:当用户输入任何用户名时,如果用户名在数据库中,它将打印“标志”,如果不在数据库中或用户不输入任何内容,它将“不在这里打印”, 因此,当我运行这段代码并尝试输入一些datbase中没有的用户名,并尝试将其保留为空白时,我发现了这个错误 def displayResult(self): name = input("> ") self.cursor.execute("SELECT username FROM customer Where username =
def displayResult(self):
name = input("> ")
self.cursor.execute("SELECT username FROM customer Where username = '%s' " % name)
if name in self.cursor.fetchone():
print("flag")
elif name not in self.cursor.fetchone():
print("Not in here.")
elif name == "" or name == " ":
print("Input something.")
如何关闭此错误警告
谢谢在尝试迭代之前,请尝试检查
fetchone
的返回值,例如:
TypeError: argument of type 'NoneType' is not iterable
在尝试迭代之前,请尝试检查
fetchone
的返回值,例如:
TypeError: argument of type 'NoneType' is not iterable
我明白了,谢谢,但我还是不明白,为什么self.cursor.fetchone()值是None?我明白了,谢谢,但我还是不明白,为什么self.cursor.fetchone()值是None?。