在 mysql 中插入一个 python 列表

Insert into mysql a python list

我尝试了很多次用 Whosebug 中的其他问题来解决我的问题,但都没有成功。我现在正在学习 python。

我知道如何在 PHP 中完成,但我需要在 python 中完成。

我有一个 table dentistas 有 4 列 id、web、email、telefono。

然后我从另一个文件导入一个包含网址的列表。

我想在 web 列中插入那些 websurl。

我现在使用的代码不会在终端中显示错误,但不会向 table:

中插入任何内容
# coding=utf-8
import MySQLdb
from parser import lista

bd = MySQLdb.connect('localhost', 'testuser', 'test123', 'leads') # Connecting to the database
cursor = bd.cursor()         # Creating the cursor 

for x in lista:
    cursor.execute("INSERT INTO dentistas(web) VALUES(%s)", (x,))

您忘记commit()并保存您当前的数据库状态。

尝试在循环后使用 bd.commit()