Python mysql在sql insert语句中写入变量

Python mysql在sql insert语句中写入变量,python,mysql,sql,Python,Mysql,Sql,我有一个名为“情绪”的表格,有日期、积极、消极和中立列 如何编写sql查询,以便在下面的代码中插入日期值 我认为问题在于datetime值的%s,因为除date之外的所有其他列的%s值都可以插入。 下面的代码返回一个sql语法错误 for item in list_of_dates: d['Period'].append(datetime.datetime.fromtimestamp(int(item)/1000).strftime('%Y-%m-%d

我有一个名为“情绪”的表格,有日期、积极、消极和中立列

如何编写sql查询,以便在下面的代码中插入日期值

我认为问题在于datetime值的%s,因为除date之外的所有其他列的%s值都可以插入。 下面的代码返回一个sql语法错误

     for item in list_of_dates: 
     d['Period'].append(datetime.datetime.fromtimestamp(int(item)/1000).strftime('%Y-%m-%d             %H:%M:%S'))

     combined_list=zip(d['period'],d['Positive'],d['Negative'],d['Neutral'])


     with con:
       cur = con.cursor()

     for x,y,w,z in combined_list:
        cur.execute("INSERT INTO sentiments(%s,%s,%s,%s) VALUES(%s,%s,%s,%s)" 
        %("Date","Positive","Negative","Neutral",str(x),str(y),str(w),str(z)))

查询的问题在于值。它应该为所有%s提供小报价,如下所示

VALUES('%s','%s','%s','%s')