2017-07-23 96 views
0

我对着错误信息pymsql +没有足够的论据格式字符串+通过列表

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 

有任何人的任何信息?

回答

0

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

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接口

相关问题