How to change the default single quotes in the executemany method in Python's MySQLdb library?
滿天的星座
滿天的星座 2017-05-18 10:48:40
0
1
626

I need to create hundreds of tables. The table names are: abc_1, abc_2, abc_3...
I used execute to create them before, but I thought it was a bit slow, so now I thought about whether I could use executemany, and then I found that executemany would use single parameters for the parameters. enclosed in quotation marks,

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

But our library does not allow table names or field names to be enclosed in single quotes, resulting in a direct error.

滿天的星座
滿天的星座

reply all(1)
给我你的怀抱

Try removing the symbols before and after %s in your statement create table %s (id int(10));.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!