首页  >  问答  >  正文

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

我需要创建上百个表,表名是: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_'` ( #创建成功,但创建的表名多出两个单引号

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

滿天的星座滿天的星座2687 天前637

全部回复(1)我来回复

  • 给我你的怀抱

    给我你的怀抱2017-05-18 10:50:40

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

    回复
    0
  • 取消回复