Skip to content Skip to sidebar Skip to footer

Update Table In Mysql Using Python Dict

I have a dictionary of values where the keys are the column names. I want to send a single update statement that included all of the data to update. I loop through the dict keys an

Solution 1:

Change your SQL

sql = 'UPDATE '+table+' SET {} WHERE cart_SN = '.format(', '.join('{}=%s'.format(k) for k in cart))+sn

Because in your case

sql = 'UPDATE '+table+' SET {} WHERE cart_SN = '+sn+' '.format(', '.join('{}=%s'.format(k) for k in cart))

format is applied to ' '.fomat() empty string not the main string

Post a Comment for "Update Table In Mysql Using Python Dict"