文章詳情頁
python的MySQLdb庫中的executemany方法如何改變默認加上的單引號?
瀏覽:66日期:2022-07-21 16:40:34
問題描述
我需要創建上百個表,表名是: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前后的符號去掉試試。
相關文章:
排行榜
