我正在尝试将数据插入sqlite3表。我一直在尝试在网上找到的多个解决方案,但似乎找不到有效的解决方案。 我的错误是
File "C:/Users/jaicedecelis/PycharmProjects/Terminal CRM/main.py", line 29, in <module>
new_customer_entry()
File "C:/Users/jaicedecelis/PycharmProjects/Terminal CRM/main.py", line 20, in new_customer_entry
(firstname, lastname, stocknumber, emailaddress, phonenum1, phonenum2, phonenum3, leaseorbuy))
TypeError: 'str' object is not callable
这是我的代码
import sqlite3
conn = sqlite3.connect("customerList.db")
c = conn.cursor()
def new_customer_entry():
firstname = input("First Name: ")
lastname = input("Last Name: ")
stocknumber = input("Stock Number: ")
emailaddress = input("Email Address: ")
phonenum1 = input("Cell Number: ")
phonenum2 = input("House Number: ")
phonenum3 = input("Work Number: ")
leaseorbuy = input("Lease or Buy?: ")
c.execute('CREATE TABLE IF NOT EXISTS customerProfiles(firstname, lastname, stocknumber, emailaddress, cellphone, housephone, workphone, leaseorbuy)')
c.execute("INSERT INTO customerProfiles (firstname, lastname, stocknumber, emailaddress, cellphone, housephone, workphone, leaseorbuy) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
(firstname, lastname, stocknumber, emailaddress, phonenum1, phonenum2, phonenum3, leaseorbuy))
conn.commit()
conn.close()
print("Customer Profile Added for " + firstname + " " + lastname)
print("Welcome to Atlantic Terminal CRM")
selection = input("N : New, S : Search\n")
if selection == "N" or selection == "n":
new_customer_entry()
# elif selection == "S" or selection == "s":
# criteria = input("F : First Name, L: Last Name, S: Stock Number, P: Phone Number\n")
# if criteria == "f" or criteria == "F":
# fName = input("First Name: ")
# if criteria == "l" or criteria == "L":
# lName = input("Last Name: ")
# if criteria == "s" or criteria == "S":
# sNum = input("Stock Number: ")
# if criteria == "p" or criteria == "P":
# pNum = input("Phone Number: ")
答案 0 :(得分:0)
您在第20行的末尾缺少逗号。
c.execute("INSERT INTO customerProfiles (firstname, lastname, stocknumber, emailaddress, cellphone, housephone, workphone, leaseorbuy) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(firstname, lastname, stocknumber, emailaddress, phonenum1, phonenum2, phonenum3, leaseorbuy))
(因为您将在下一行继续执行c.execute()块的其余部分。)