How to update mysql with python where fields and entries are from a dictionary?

后端 未结 2 663
太阳男子
太阳男子 2020-12-31 14:46

I am trying to create a re-usable mysql statement for updating from a dictionary where the keys are the database fields and the data to go into that field is the value assoc

2条回答
  •  猫巷女王i
    2020-12-31 15:44

    how about trying

    stmt = "UPDATE TABLE table_name SET "
    for k,v in di.items():
        stmt += "%s = %s, " %(k,v)
    
    stmt = stmt[-2:]
    

提交回复
热议问题