Table has already been created. Problem arising while inserting values into it. Format method not working fine.
classroom_data = [
{1,"Raj","M",70,84,92},
{2,"Ajay","M",75,92,42},
{3,"Alex","M",62,42,61},
{4,"Smita","F",49,50,46},
{5,"Palak","F",84,62,44}]
connection = sql.connect("classroom.db")
cursor = connection.cursor()
for s in classroom_data:
insert_statement = """ INSERT INTO classroom
(student_id,name,gender,phy_mks,chm_mks,math_mks)
VALUES
({0}, "{1}" ,"{2}", {3},{4},
{5});""".format(s[0],s[1],s[2],s[3],s[4],s[5])
cursor.execute(insert_statement)
connection.commit()
connection.close()
Error:
TypeError Traceback (most recent call last)
<ipython-input-33-2e24144d045c> in <module>()
12 (student_id,name,gender,phy_mks,chm_mks,math_mks)
13 VALUES
---> 14 ({0}, "{1}","{2}", {3}, {4}, {5});""".format(s[0],s[1],s[2],s[3],s[4],s[5])
15
16 cursor.execute(insert_statement)
TypeError: 'set' object does not support indexing