title: which is the best way to insert values in mysql via python scripts in a loop
body: <p>I have the backup script like below</p>
  
  <pre><code>for f in os.listdir(path)
    // do backup
  </code></pre>
  
  <p>Now i want to insert in mysql values like foldername , date , size etc</p>
  
  <p>This is mysql script</p>
  
  <pre><code>sql = "INSERT INTO pythontest(name, \
         name2, name3) \
         VALUES ('%s', '%s', '%s')" % \
         ('Mac', 'Mohan', '')
  try:
     # Execute the SQL command
     cursor.execute(sql)
     # Commit your changes in the database
     db.commit()
  except:
     # Rollback in case there is any error
     db.rollback()
  </code></pre>
  
  <p>Now i am not sure whether insert full code in for loop or make a function of it</p>