title: dynamic mysql insert statement in python
body: <p>I need to update columns values in csv to mysql database and the csv values are dynamic for one file it may be 10 columns and for other it may be 5 columns.</p>
  
  <p>my understanding in python we need to use list also this question raised earlier is similar to my requirement but here the values are static so it can be predefined where's in my case being dynamic need to a solution to have %%s under VALUES to be multiplied according to my column values dynamically.</p>
  
  <p><a href="https://stackoverflow.com/questions/6589414/mysql-dynamic-query-statement-in-python">MySQL Dynamic Query Statement in Python</a></p>
  
  <pre><code>   ds_list=['name','id','class','chapter','MTH','YEAR']
  
     vl_list=['xxxxx','978000048','x-grade','Science',mar,2017]
  
     sql = 'INSERT INTO ann1 (%s) VALUES (%%s, %%s, %%s, %%s, %%s, %%s)' %    ','.join(ds_list)
  
     cur.execute(sql, vl_list)
  
     conn.commit()
  </code></pre>