Answers for "how to insert values to database with using dictionary in python"

0

how to insert values to database with using dictionary in python

placeholders = ', '.join(['%s'] * len(myDict))
columns = ', '.join(myDict.keys())
sql = "INSERT INTO %s ( %s ) VALUES ( %s )" % (table, columns, placeholders)
# valid in Python 2
cursor.execute(sql, myDict.values())
# valid in Python 3
cursor.execute(sql, list(myDict.values()))
Posted by: Guest on February-18-2022

Code answers related to "how to insert values to database with using dictionary in python"

Python Answers by Framework

Browse Popular Code Answers by Language