【发布时间】:2016-08-16 07:29:36
【问题描述】:
我正在尝试使用 pymysql (Python 3) 在 MySQL 表上插入行,相关代码如下。
def saveLogs(DbConnection, tableName, results):
for row in results:
formatStrings = ",".join(["?"]*len(row))
sql = "INSERT INTO %s VALUES (%s);"%(tableName,formatStrings)
DbConnection.cursor().execute(sql, tuple(row))
DbConnection.commit()
我使用"?" 作为类型,但收到错误not all arguments converted during string formatting。 row 是由strings、ints 和datetime.datetime 组成的列表。我想问题是"?",但我已经检查了 PEP 249,但我仍然不清楚我应该怎么做。有什么建议吗?
【问题讨论】:
标签: python mysql python-3.x pymysql