Python - 将 300 个变量插入 SQLite

Python - Insert 300 variables into SQLite

我每分钟从热传感器接收到 300 个值。这 300 个值需要插入到 SQLite 数据库中,因为它们每分钟接收一次。

我在 SQLite 数据库中创建了 302 行,第一列是 S_ID,第二列是 timestamp。在这里,每添加一行,S_ID 就会自动递增,timestamp 列的默认值是当前系统时间。我已经编程为每分钟接收 300 个热传感器值,将所有 300 个值放入名为 data 的列表中,然后将 data 插入数据库。现在,我需要知道如何在不写下所有 300 列名称和 ? 的情况下编写 executemany 语句。

data = [(300, 2, 4, ..., 5.5)] #these are 300 values that are inserted into a list when received from heat sensor
c.executemany('INSERT INTO heat_table (col3, col4, ..., col302) VALUES (?, ?, ..., ?)', data)

我会使用列表理解创建这些名称,然后加入它们:

query = ('INSERT INTO heat_table (' +
         ', '.join('col%d' % i for i in range(3, len(data) + 3)) +
         ') VALUES (' +
         ', '.join('?' * len(data)) +
         ')')