我正在 Kivy 中创建一个 Python 程序,它允许用户登录或创建一个新帐户。我在 MySQL 中有一个 Python 程序引用的用户名和密码表(通过 PyMySQL)。当新用户输入一个已经存在的用户名时,Python 会遍历 MySQL 表中的每个用户名,如果用户名已经存在,Python 会要求用户输入一个新密码。问题是,当用户尝试输入新用户名并且 Python 再次运行代码时,我收到“TypeError: 'unicode' object is not callable”。我很困惑,因为如果用户第一次输入一个不存在的用户名,我不会出错。当他们再次尝试输入用户名时,我收到错误消息。
这是我的 .py 主文件代码块,它给我带来了问题:
#Select all usernames from the database with the execute method
cur.execute("""SELECT username FROM patient_login""")
#Use the fetchall() method to get a list dictionary of all usernames
self.usernames_from_db = cur.fetchall()
#For each of the names in the list/dict of usernames
for names in self.usernames_from_db:
#If the names username is equal to the username the user created
if …Run Code Online (Sandbox Code Playgroud)