将python脚本从sqlite3更改为mysq的语法

2024-09-27 07:23:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个工作的python脚本,它从sqlite3db检索数据。我需要把它转换成一个mysql数据库,这里的第一行让我很难过:

PRODUCT_CODE_ID = "SELECT id FROM localsite_productcode WHERE localsite_productcode.product_code=?"
cur.execute(PRODUCT_CODE_ID,(product_code,))

当我尝试使用mysql时,会出现以下错误:

Traceback (most recent call last):
  File "gen-csv.py", line 85, in <module>
    cur.execute(PRODUCT_CODE_ID,(product_code,))
  File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 151, in execute
    query = query % db.literal(args)
TypeError: not all arguments converted during string formatting

我做错什么了?你知道吗


Tags: inpyidexecutelinemysqlcodeproduct

热门问题