在数据库SQLite3中插入字典



这里我试图在SQLite数据库中放入一个字典

data1 = {
'x': x,
'y': y,
'width': width,
'height':height,
'proba': proba,
'class': label,
'id_label': id_label
}

sqliteConnection = sqlite3.connect('SQL_bdd.db')
cursor = sqliteConnection.cursor()
sqliteConnection.execute('''CREATE TABLE dic (
x        INT           NOT NULL,
y        INT           NOT NULL,
width    INT           NOT NULL,
height   INT           NOT NULL,
proba    BOOLEAN       NOT NULL,
class    VARCHAR (255) NOT NULL,
id_label INT           NOT NULL
);''')

cursor.execute('INSERT INTO dic VALUES (?,?,?,?,?,?,?)', [dict['x'], dict['y'], dict['width'], dict['height'], dict['proba'], dict['class'], dict['id_label']]);
cursor.execute("SELECT * FROM dic")

出现以下错误,我不知道如何修复

cursor.execute('INSERT INTO dic VALUES(;

TypeError:"type"对象不是可下标的

使用data1['x']、data1['y']等来索引data1字典中的数据,而不是dict['x']、dict['y']等。

最新更新