0

我正面临错误消息

TypeError: not enough arguments for format string

这是我的代码

for data in zip(link_hash, link, headline, snippit, rubID, date, time):
    pass

if not sql_one_empty:
    sql_insert_hash = """ INSERT INTO ntv (link_hash, link, headline, snippit, rubID, date, time) VALUES (%s, %s, %s, %s, %s, %s, %s)"""

    cur.executemany(sql_insert_hash, data)
else:
    pass

完整的错误回溯:

Traceback (most recent call last):
  File "/home/unixben/Development/python/mySQL_save.py", line 45, in <module>
    cur.executemany(sql_insert_hash, data)
  File "/usr/local/lib/python3.5/dist-packages/pymysql/cursors.py", line 193, in executemany
    self._get_db().encoding)
  File "/usr/local/lib/python3.5/dist-packages/pymysql/cursors.py", line 209, in _do_execute_many
    v = values % escape(next(args), conn)
TypeError: not enough arguments for format string

有人有任何信息吗?

4

2 回答 2

1

数据应包含 7 个元素(每个 %s 一个)。它可能没有。

于 2017-07-23T07:31:45.203 回答
0

所以我有几个 txt 文件

with open("temp_link.txt") as temp_link, \
     open("temp_LinkHash.txt") as temp_hash, \
     open("temp_headline.txt") as temp_headline, \
     open("temp_snippet.txt") as temp_snippit, \
     open("temp_rubID.txt") as temp_rubID, \
     open("temp_date.txt") as temp_date, \
     open("temp_time.txt") as temp_time:
     link_url = temp_link.readlines()
     hash_url = temp_hash.readlines()
     headline = temp_headline.readlines()
     snippit = temp_snippit.readlines()
     rubID = temp_date.readlines()
     date = temp_time.readlines()
     time = temp_rubID.readlines()

加载然后通过 zip 函数合并,但不幸的是我完全收到上述错误消息,是否有 7 个字段,因为“executemany”而完全符合预期?因为 readlines() 返回一个列表

with open("temp_link.txt") as temp_link, \
     open("temp_LinkHash.txt") as temp_hash, \
     open("temp_headline.txt") as temp_headline, \
     open("temp_snippet.txt") as temp_snippit, \
     open("temp_rubID.txt") as temp_rubID, \
     open("temp_date.txt") as temp_date, \
     open("temp_time.txt") as temp_time:
     link_url = temp_link.readlines()
     hash_url = temp_hash.readlines()
     headline = temp_headline.readlines()
     snippit = temp_snippit.readlines()
     rubID = temp_date.readlines()
     date = temp_time.readlines()
     time = temp_rubID.readlines()


for data in zip(hash_url, link_url, headline, snippit, rubID, date, time):
    pass

print(data)


if not sql_one_empty:
    sql_insert_hash = " INSERT INTO ntv (hash_url, link_url, headline, snippet, rub_id, datum, time) VALUES (%s, %s, %s, %s, %s, %s, %s)"
    cur.executemany(sql_insert_hash, data)
    db.commit()
else:
    pass

我真的有点绝望,有了MySQL的界面

于 2017-07-23T08:47:25.117 回答