Search
 
SCRIPT & CODE EXAMPLE
 

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()))
Comment

PREVIOUS NEXT
Code Example
Python :: to get the number of unique values for each column 
Python :: python source code 
Python :: how to delete item in string python 
Python :: numeric up down python tkinter 
Python :: Python NumPy stack Function Example with 2d array 
Python :: django run manage.py from python 
Python :: python dlib 
Python :: python How do you find the middle element of a singly linked list in one pass? 
Python :: python if string has spaces 
Python :: add two dataframes together 
Python :: sns swarm plot 
Python :: gfg placement course 
Python :: defining function in python 
Python :: using hashlib module in python 
Python :: python dataframe add rank column 
Python :: How to Get the Symmetric Difference of Sets in Python 
Python :: python get pattern from string 
Python :: python random.sample 
Python :: print string python 
Python :: extract numbers from list of strings python using regex 
Python :: python single vs double quotes 
Python :: use latest file on aws s3 bucket python 
Python :: convert string to integer in python 
Python :: boto3 rename file s3 
Python :: local time in python 
Python :: return the biggest even fro a list python 
Python :: how to do input python 
Python :: python int in list 
Python :: dataframe, groupby, select one 
Python :: python dynamic variable name 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =