Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insert a Python list into a column in MySQL

I have list and I want to enter each element of that list into associated indexed cells of a column in MYSQL using Python.

E.g

lst = [11,22,33,44,55,66]

MYSql column:

Data
11
22
33
44
55
66.

How can I achieve this.

like image 421
cryp Avatar asked Jun 27 '26 15:06

cryp


1 Answers

Following code will do the work:

values = [list([item]) for item in lst]
cursor.executemany(u'INSERT INTO `tbl`(`Data`)(%s)', values)
like image 171
schemacs Avatar answered Jun 30 '26 08:06

schemacs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!