I have list instead some value. I want to split the value of the list and insert into different column.
def insert_data(daftar):
query = "INSERT INTO citra(img_source,fitur_0,fitur_1,fitur_2,fitur_3,fitur_4,fitur_5) " \
"VALUES(%s,%s,%s,%s,%s,%s,%s)"
try:
db_config = read_db_config()
conn = MySQLConnection(**db_config)
cursor = conn.cursor()
cursor.executemany(query, daftar)
conn.commit()
except Error as e:
print('Error:', e)
finally:
cursor.close()
conn.close()
def main():
for x in range(len(list)):
list[x]
result = str(list).strip('[]')
daftar = [(file,result)]
print daftar
insert_data(daftar)
if __name__ == '__main__':
main()
when I compile the code
[('E:/py/BatikTest/B43_1.jpg', '0, 0, 0, 92, 57, 5')]
I got error
('Error:', ProgrammingError(-1, 'Not enough parameters for the SQL statement', None))
I think the value still in one list. Is possible to split the value and insert into different column?
[('E:/py/BatikTest/B43_1.jpg', '0, 0, 0, 92, 57, 5' )]
Remove quotes. Right code is:
[('E:/py/BatikTest/B43_1.jpg', 0, 0, 0, 92, 57, 5)]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.