【发布时间】:2013-03-13 13:46:14
【问题描述】:
我正在尝试使用 Python MySQLConnector 将包含数字的集合附加到我的 MySQL 数据库中。我可以手动添加数据,但以下带有 %s 的表达式将不起作用。我对此尝试了几种变体,但文档中的任何内容似乎都不适用于我的情况。如您所见,该表已经构建:
#Table erstellen:
#cursor.execute('''CREATE TABLE anzahlids( tweetid INT )''')
这是我的代码和错误:
print len(idset)
id_data = [
len(idset)
]
print id_data
insert = ("""INSERT INTO anzahlids (idnummer) VALUES (%s)""")
cursor.executemany(insert, id_data)
db_connection.commit()
"处理格式参数失败;%s" % e)
mysql.connector.errors.ProgrammingError:处理格式参数失败; map() 的参数 2 必须支持迭代
【问题讨论】:
-
哎呀。磨损的桌子。正确的是: cursor.execute('''CREATE TABLE anzahlids( idnummer INT )''') 在代码中它是正确的。
-
请发一个idset中的数据示例
-
idset 是一个 id 列表。这些 id 是数字。但我想将
len(idset)插入到数据库中。 -
插入语句与表定义不匹配。请参阅我的答案中的示例。
标签: python mysql mysql-python mysql-connector