insert a Python list into a column in MySQL

北城以北 提交于 2019-12-10 10:26:58

问题


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.


回答1:


Following code will do the work:

values = [list([item]) for item in lst]
cursor.executemany(u'INSERT INTO `tbl`(`Data`)(%s)', values)


来源:https://stackoverflow.com/questions/16225128/insert-a-python-list-into-a-column-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!