Skip to content

Instantly share code, notes, and snippets.

@buptxge
Created March 15, 2016 07:38
Show Gist options
  • Save buptxge/711ab5a5a91f29406a0b to your computer and use it in GitHub Desktop.
Save buptxge/711ab5a5a91f29406a0b to your computer and use it in GitHub Desktop.
Python MySQLdb insert code by dict(key-value)
placeholders = ', '.join(['%s'] * len(myDict))
columns = ', '.join(myDict.keys())
sql = "INSERT INTO %s ( %s ) VALUES ( %s )" % (table, columns, placeholders)
cursor.execute(sql, myDict.values())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment