Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyMySQL:在查询中使用对象_Python_Mysql_Pymysql - Fatal编程技术网

Python PyMySQL:在查询中使用对象

Python PyMySQL:在查询中使用对象,python,mysql,pymysql,Python,Mysql,Pymysql,我在aws lambda函数中使用pymysql对我的数据库执行一些查询。我通常是这样做的 query = f"INSERT INTO a (col_1, col_2) VALUES ('{event['col_1']}', '{event['col_1']}'" cursor.execute(query) db.commit() 这对于列数较少的表是可行的。假设我的表有12列,那么我需要键入event['col_1']、event['col_2']、event['col_

我在aws lambda函数中使用pymysql对我的数据库执行一些查询。我通常是这样做的

query = f"INSERT INTO a (col_1, col_2) VALUES ('{event['col_1']}', '{event['col_1']}'"
cursor.execute(query)
db.commit()
这对于列数较少的表是可行的。假设我的表有12列,那么我需要键入event['col_1']、event['col_2']、event['col_3']等等。是否有任何帮助程序库可以接受col_1、col_2、col_3。。。作为一个对象,做同样的事情,而不是写所有的东西。最有可能把科尔斯当作一个对象

PS:labmda函数看起来像这样

def lambda_handler(event, context):
    ...