我有我的Python代碼如下的結果:如何插入一個表包含多個字典到MySQL表中?
[
{filename:'1,2',Name:'Gorge',registration number: '6657', registration date: '2012-09-10 14:31:13'},
{filename:'5,43',Name:'mazu',registration number:'45', registration date:'2012-10-08 17:28:47'}]
,一旦我希望把它放在一個MySQL表,我得到這個錯誤:
Traceback (most recent call last):
File "C:\Users\jio\Datasets 1\MyTable_info.py", line 63, in <module>
cur.executemany(query,records)
File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 243, in executemany
self.errorhandler(self, ProgrammingError, msg.args[0])
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: not enough arguments for format string
我的Python代碼中插入結果在MySQL表爲下面的代碼:
con = MySQLdb.connect(host = "******", port=***, user = "***", passwd="*****", db="****")
with con:
cur=con.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS info(id INT(10) auto_increment primary key,file_name VARCHAR(10),
Name VARCHAR(50),Registration ID INT(50),registration time INT(50))''')
query= "INSERT INTO info (file_name, Name, Registration ID, registration time) VALUES (%s, %s, %s, %s)"
cur.executemany(query,records)
con.commit()
有沒有人有一個想法,爲什麼我得到這個錯誤又是什麼錯誤呢?
記錄內容就是我上面粘貼的結果。每個文件都有其中之一。我正在瀏覽一個目錄。 – UserYmY 2013-04-25 07:30:56