您的位置:首页技术文章
文章详情页

python的MySQLdb库中的executemany方法如何改变默认加上的单引号?

【字号: 日期:2022-07-21 16:40:34浏览:47作者:猪猪

问题描述

我需要创建上百个表,表名是:abc_1、abc_2、abc_3……之前用execute创建,觉得有些慢,于是现在考虑能不能用executemany,然后发现executemany会把参数用单引号括起来,

>>cur.execute(’’’create table %s (id int(10));’’’,(’abc_1’,))create table ’abc_1’ ( #单引号抛出异常>>cur.execute(’’’create table `%s` (id int(10));’’’,(’abc_1’,))create table `’abc_’` ( #创建成功,但创建的表名多出两个单引号

但是我们的库不允许用单引号括起来表名或字段名,导致直接报错。

问题解答

回答1:

你把你语句create table %s (id int(10));中%s前后的符号去掉试试。

标签: Python 编程
相关文章: