Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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()))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #insert #values #database #dictionary #python
ADD COMMENT
Topic
Name
4+5 =