d = {'name':'alx','age':18,'pp':11,'cc':12} sql = '''insert into xx(%s) value(%s)''' key_list = [] value_list=[] for k,v in d.items(): key_list.append(k) value_list.append('%%(%s)s' % k) sql = sql % (','.join(key_list),','.join(value_list)) cursor.execute(sql,d)