Not sure what I'm missing here but this code runs without any error message, but there's nothing in the table. I'm loading a CSV values in three columns into mysql table
import csv
import MySQLdb
mydb = MySQLdb.connect(host='localhost',
user='root',
passwd='',
db='mydb')
cursor = mydb.cursor()
csv_data = csv.reader(file('students.csv'))
for row in csv_data:
cursor.execute('INSERT INTO testcsv(names,
classes, mark )'
'VALUES("%s", "%s", "%s")',
row)
#close the connection to the database.
cursor.close()
print "Done"
Would appreciate if someone else could have a look.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…