AttributeError: 'function' object has no attribute 'connect'
AttributeError: 'function' object has no attribute 'connect'
我正在尝试将数据插入到我已经创建的 sqlite3 数据库中。可以输入数据。但是,当尝试连接到我的数据库并保存时,我收到一条错误消息“AttributeError:'function' object has no attribute 'connect'”
我的代码片段如下:
def data_entry():
option_choice=0
call("clear")
print"\t","\n"*4
print"\t","-"*45
print"\t","\t-- Data Entry --"
ID = raw_input("what is your user ID?")
Name = raw_input("What is your name?")
Age = raw_input("how old are you?")
incidents = raw_input("How many incidents have you been involved in?")
physical_ability = raw_input("what is your physical driving state?")
Address = raw_input("what is your address?")
Tel = raw_input("what is your phone number?")
datestamp = raw_input("What is today's date?")
keyword = raw_input("What is the make of your vehicle?")
monthly_salary = raw_input("How much do you earn each month?")
conn = db.connect('Insurance_Shark.db')
cursor = conn.cursor()
cursor.execute("INSERT INTO customerdatabase VALUES(?, ?, ?, ?, ?, ?)",
(ID, Name, Age, incidents, physical_ability, Address, Tel, datestamp, keyword, monthly_salary))
您没有说明 db
变量是如何定义的,但看起来 它是一个函数,因为:
>>> def db():
... pass
...
>>> db.connect()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'connect'
connect()
function 可直接从 sqlite3
模块获得:
>>> import sqlite3
>>> sqlite3.connect("test.db")
<sqlite3.Connection object at 0x10d922a28>
我正在尝试将数据插入到我已经创建的 sqlite3 数据库中。可以输入数据。但是,当尝试连接到我的数据库并保存时,我收到一条错误消息“AttributeError:'function' object has no attribute 'connect'” 我的代码片段如下:
def data_entry():
option_choice=0
call("clear")
print"\t","\n"*4
print"\t","-"*45
print"\t","\t-- Data Entry --"
ID = raw_input("what is your user ID?")
Name = raw_input("What is your name?")
Age = raw_input("how old are you?")
incidents = raw_input("How many incidents have you been involved in?")
physical_ability = raw_input("what is your physical driving state?")
Address = raw_input("what is your address?")
Tel = raw_input("what is your phone number?")
datestamp = raw_input("What is today's date?")
keyword = raw_input("What is the make of your vehicle?")
monthly_salary = raw_input("How much do you earn each month?")
conn = db.connect('Insurance_Shark.db')
cursor = conn.cursor()
cursor.execute("INSERT INTO customerdatabase VALUES(?, ?, ?, ?, ?, ?)",
(ID, Name, Age, incidents, physical_ability, Address, Tel, datestamp, keyword, monthly_salary))
您没有说明 db
变量是如何定义的,但看起来 它是一个函数,因为:
>>> def db():
... pass
...
>>> db.connect()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'connect'
connect()
function 可直接从 sqlite3
模块获得:
>>> import sqlite3
>>> sqlite3.connect("test.db")
<sqlite3.Connection object at 0x10d922a28>