在Python中将字符串分割为两个变量时出现错误

2024-09-29 23:16:03 发布

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

我需要能够在一个输入框中输入一个用户的全名,然后将其拆分为firstname和surname变量,这样这些变量就可以用来在数据库中搜索。然而,我有这个问题,因为这是我没有真正做过。感谢您的帮助

    studentname = (StudName.get())
    conn = sqlite3.connect('MyComputerScience.db')
    c = conn.cursor()
    firstName, lastName = studentname.split()
    namesearchadd = (firstname, lastname,)
    c.execute ("SELECT * FROM users WHERE FName = ? and SName= ? VALUES (?,?);", (namesearchadd,))
    data = c.fetchall()
    if len(data) == 0:
        print ("whoops")
    else:
        Label(screen6, text = "Success", fg="GREEN").place(relx=0.101, rely=0.725, height=21, width=194) 

firstName, lastName = studentname.split()
ValueError: not enough values to unpack (expected 2, got 0)

Tags: 用户数据库datagetsurnamefirstnameconnsqlite3

热门问题