https://drive.google.com/open?id=1aQkJYojDNMjNjJYlggxbkTq-KmzALDDb
我有这个文件(citations.dmp),我试图插入由 | 分隔的数据 使用以下代码进入mysql数据库:
import MySQLdb
file = open('citations.dmp', 'r').readlines()
list = []
for x in file:
a = str(x.replace('\t', ''))
a = str(a).split('|')
a.pop(len(a) - 1)
list.append(a)
db = MySQLdb.connect(
host='127.0.0.1',
user='root',
passwd='',
db='tururu'
)
c = db.cursor()
print('Inserting...')
query = """ INSERT INTO `citations` (`cit_id`,`cit_key`,`pubmed_id`,`medline_id`,`url`,`text`,`taxid_list`)
VALUES (%s,%s,%s,%s,%s,%s,%s)
"""
c.executemany(query, list)
db.commit()
db.close()
该表的格式如下:
CREATE TABLE `citations` (
`cit_id` VARCHAR(200) NULL,
`cit_key` VARCHAR(200) NULL,
`pubmed_id` VARCHAR(200) NULL,
`medline_id` VARCHAR(200) NULL,
`url` LONGTEXT NULL,
`text` LONGTEXT NULL,
`taxid_list` LONGTEXT NULL);
出于某种原因,我每次都会收到以下错误:
Traceback (most recent call last):
File "C:/Users/lucas/PycharmProjects/bruno/tst.py", line 27, in <module>
c.executemany(query, list)
File "C:\ProgramData\Anaconda3\lib\site-packages\MySQLdb\cursors.py", line 281, in executemany
self._get_db().encoding)
File "C:\ProgramData\Anaconda3\lib\site-packages\MySQLdb\cursors.py", line 306, in _do_execute_many
v = values % escape(arg, conn)
TypeError: not all arguments converted during string formatting
你能帮助我吗?我在过去 3 天试图修复它。