我有一个问题。当我执行整个事情时,它会抛出一个错误说明:TypeError:没有足够的格式字符串参数。我想这与cur.execute中的错误有关(“INSERT INTO modules
(module_name,no_of_scripts,gsm,exam_type,exam_date,school)VALUES(%s,%s,%s,%s, %s,%s)“)但不确定可能导致问题的原因。请帮助谢谢!
以下是参考代码:
db = MySQLdb.connect(host='localhost',
user="schooluser",
passwd="",
db="exam_import")
cur = db.cursor()
csv_data = csv.reader(file('Modules.csv'))
for row in csv_data:
cur.execute("INSERT INTO `modules`(module_name, no_of_scripts, gsm, exam_type, exam_date, school) VALUES (%s, %s, %s, %s, %s, %s)")
cur.execute("SELECT * FROM modules")
for row in cur.fetchall():
self.name = row[0]
self.sheetsperpaper = row[1]
self.paperweightlol = row[2]
self.exam_type1 = row[3]
self.exam_series1 = row[4]
self.exam_school1 = row[5]
self.module_name.append(self.name)
self.sheets.append(self.sheetsperpaper)
self.paperweight.append(self.paperweightlol)
self.exam_type.append(self.exam_type1)
self.exam_series.append(self.exam_series1)
self.exam_school.append(self.exam_school1)
db.commit()
db.close()
答案 0 :(得分:0)
您需要为查询设置值
λ Nothing : [ Just 1, Nothing ]
[Nothing,Just 1,Nothing]
所以你将行的每一列的值设置为你的查询(如果顺序不是那样,你可以改变行[x]的位置)