【问题标题】:SQLite3 Python inserting multiple listsSQLite3 Python插入多个列表
【发布时间】:2019-01-30 17:04:36
【问题描述】:

我正在为我的母语开发自然语言工具包。我想使用 SQLite3 创建新数据库。 我做了 4 列的空表。每列有 4 个包含数据的列表。

在我尝试过的许多变体中:

conn = sqlite3.connect(db_file)
with conn:
 cur = conn.cursor()
 for i in range(len(dataTxt)):
    dataList = (L1[i], L2[i], L3[i], L4[i])

    sql = ''' INSERT INTO new_table(col1, col2, col3, col4)
                                         VALUES(?,?,?,?)'''                
    cur.execute(sql, dataList )

*L1 存放整数和 L2-L4 字符串, 但得到错误:

sqlite3.InterfaceError:错误绑定参数 1 - 可能是不支持的类型。

【问题讨论】:

  • L1 可能包含无法转换为 sqlite 类型的值。
  • @Shawn 它包含 int
  • 该类型不会导致显示的错误消息。 type(L1[i]) 是什么?

标签: python-3.x sqlite


【解决方案1】:
cur.execute(sql, (L1[i],...,L4[i]) )

在for 周期内工作。

显然.execute 只取两个值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-27
    • 2016-09-20
    • 1970-01-01
    • 2016-01-06
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多